Strapi : An error occurred during models config fetch - content-management-system

I was using strap 3.0.0.next-11 and then migrated my APIs to 3.6.8 version.
In 3.6.8 i see this error in a pop-up , for collections which has relations:
An error occurred during models config fetch.
on logs i see this error :
Cast to ObjectId failed for value "http://54.179.156.135:1339/uploads/d26af51633f2451a934896bfc125ec90.jpg" at path "_id" for model "file"
Why is this happening on 3.6.8 ? I have been using the older version without any issues and with this new version I am unable to feth anything.
I am using following :
node : 14.17.6 (LTS)
npm : 6.14.15
strapi : 3.6.8
I have also attached the image of my package.json.

So I figured out the reason why this was happening in my case. After migrating to 3.6.8 , the fields in model which have type :
"thumbnail": {
"model": "file",
"via": "related",
"plugin": "upload"
}
need to have values stored as ObjectId in database as a reference to an entry in upload_file which is maintained by strapi internally.
earlier, thumbnail would store value as a string url ( url of the image ).
Example :
thumbnail : https://my_image_url_path/img.jpg
Now , thumbnail stores the reference i.e. ObjectId , which refers to an entry in the upload_file collection which is responsible for maintaining all the images uploaded via strapi upload api.
Example :
thumbnail : ObjectId("60f53bf69f811d268d8fedb1")

Related

Mapping/Joining Not Working - Mongoosastic/Mongoose

Enviroment
mongoosastic version: 4.4.1
node version: 7.10.1
mongoose version: 4.11.7
elasticsearch version: 6.4.0
Expectation:
Post Model:
{ usernames : ["5ae2cf1dd18f412bcf522750", "5abc7852f28e0b50530af785", "5b582c6b9751c9672f77324d"] }
Usermodel :
[{_id : 5ae2cf1dd18f412bcf522750, username : "temp"}]
Need to join/map user in post
If a user search the name 'temp' respective post_id should be getting searched by elasticsearch
Actual Behaviour:
Currently unable to map/join
Thanks in advance

Remote MongoDB access through Cloud 9 gives login failed exception

I'm using the Cloud 9 IDE to develop an application using MongoDB. I created a database called "appdata" at MongoLab and the following user:
{
"_id": "appdata.admin",
"user": "admin",
"db": "appdata",
"credentials": {
"SCRAM-SHA-1": {
"iterationCount": 10000,
"salt": "K/WUzUDbi3Ip4Vy59gNV7g==",
"storedKey": "9ow35+PtcOOhfuhY7Dtk7KnfYsM=",
"serverKey": "YfsOlFx1uvmP+VaBundvmVGW+3k="
}
},
"roles": [
{
"role": "dbOwner",
"db": "appdata"
}
]
}
Whenever I try connecting to the database through Cloud 9 Shell using the following command (given by MongoLab with my newly created user):
mongo ds057244.mongolab.com:57244/appdata -u admin -p admin
I get the following error message:
MongoDB shell version: 2.6.11
connecting to: ds057244.mongolab.com:57244/appdata
2015-11-22T05:23:49.015+0000 Error: 18 { ok: 0.0, errmsg: "auth failed",
code: 18 } at src/mongo/shell/db.js:1292
exception: login failed
Also, on my javascript file running on Cloud 9, while following this tutorial (which uses mongoose to access the DB) I got stuck on the post route for bears. Whenever I send a post request through postman with the specified fields set, the route doesn't return anything, neither a bear created nor an error message, which makes me think the problem is also failing to login to the database. The previous get request is working just fine and my code is the exactly same as the tutorial.
Does anyone know what the problem in any of the cases and what I need to do to solve them?
The shell problem was fixed updating it to the Database version (which was 3.0.3).
For the javascript files, I restarted the tutorial and made sure I downloaded all necessary dependencies with the most recent stable version (not the ones shown on the tutorial), after that the problem was solved.

Text search on mongodb 2.6 returning error

I'm using mongoDB 2.6 and the structure of my document is something like this:
{
"about": <about me>,
"_id" : <id>
}
I want to apply text search on about field. I did it using: db.user.ensureIndex({"about":"text"})
But when I run a search query: db.user.find({$text:{$search:"internet"}}) I get this error: error: { "$err" : "invalid operator: $search", "code" : 10068 } As per the documentation, text search is enabled on mongodb 2.6 by default. So what could be wrong? Earlier I had 2.2 installed on my machine. I recently downloaded 2.6 and I applied this index using 2.6 only.

Got unauthorized error when renaming mongodb collection

I am using mongohq sandbox plan. In the command prompt,
db["oldCollectionName"].renameCollection("newCollectionName", true)
works fine without using admin database.
However, I got "unauthorized" exception when I do this in Java:
oldCollection.rename(newCollectionName);
Since I am using mongohq sandbox plan, I don't have access to admin database. Is there a way to rename this collection without creating a new collection, copying over all the documents, and dropping the old collection?
In Java and using Jongo you can do the following:
MongoCollection col = new Jongo(DbConfigurer.getDB()).getCollection("CODE");
col.getDBCollection().rename("CODE45", true);
I've just tested and it works.
Now using the 'runCommand' (same than using db.command) in the following example:
DB db = ....getDB();
Jongo jongo = new Jongo(db);
jongo.runCommand("{ renameCollection : 'OLD_NAME', to: 'NEW_NAME', dropTarget: true}");
I obtain the same error you have.
I read from some documentation you have to connect first to admin database to process some of the command not allowed, so i did the same but with "admin" db, and i obtain the following error stack:
{ "serverUsed" : "localhost/127.0.0.1:27017" ,
"errmsg" : "exception: invalid collection name: NEW_NAME" , "code" : 15967 , "ok" : 0.0}
Strange to have such different behaviors...

Updating mongodb references errors out due to field names

I have a MongoDB collection and I'm trying to update all the entries in it to change the name of a field used to store a reference. The Query I'm using is
db.products.find().forEeach(function(p) {
p.newField = p.oldField;
db.products.save(p);
});
The problem is that p.oldField is a DBRef following the standard format of { "$ref": "collection", "$id": ObjectId("...")}. When I try to run the db.products.save(p); Mongo returns the following error:
Sat Oct 1 13:00:57 uncaught exception: field names cannot start with $ [$db]
I'm using version 1.8.2 of the MongoDB shell. I have seen this work on an older version of the shell (1.6.5), which is where I originally came up with this query. But I can't seem to make this work on newer versions.