I am encountering an error while creating a record in my Sails.js application using the UserTM.create() method with a MongoDB database. The error message states:
Error [AdapterError]: Unexpected error from database adapter: 1st argument must be a dictionary
Here’s an example of the data payload I’m trying to save:
{
"trademark": "5a99562721b803b3d6e2e2f2",
"team": "58428b2c801fe60321d48f0c",
"party": "opponent",
"precomputed_data": {},
"dontWatch": false,
"createdBy": "58428b2c801fe60321d48f15",
"brand": "66df40d5108f03c2c253876e"
}
I have checked the payload, and it seems to be in the correct format (a valid dictionary). However, the error seems to indicate that something is wrong with the data or how it’s being processed.
Error Trace:
Here is part of the stack trace for the error:
Error [AdapterError]: Unexpected error from database adapter: 1st argument must be a dictionary
at newConstructor.v.create (/path/to/sails/api/hooks/waterline/index.js:110:38)
at sails.async.auto.createUserTM (/path/to/sails/api/controllers/UserTMController.js:432:24)
at processNativeRecord (/path/to/sails/node_modules/sails-mongo/lib/private/machines/private/process-native-record.js:26:3)
My Code:
Here’s the code I’m using to create the record:
let utm = {
"trademark": "5a99562721b803b3d6e2e2f2",
"team": "58428b2c801fe60321d48f0c",
"party": "opponent",
"precomputed_data": {},
"dontWatch": false,
"createdBy": "58428b2c801fe60321d48f15",
"brand": "66df40d5108f03c2c253876e"
};
UserTM.create(utm).exec(function(err, userTm){
if (err) {return cb(err);}
return cb(null, userTm);
})
Context:
- Sails.js version: 1.5
- ORM: Waterline
- Database: MongoDB 4.4
- The error occurs during an async task when a new UserTM record is being created.
Additional Observation:
- I noticed that the document is being stored in MongoDB, but the error is still thrown.
Any help would be greatly appreciated. Thanks!
- Verified that the payload is always a valid object/dictionary.
- Checked MongoDB connection and adapter configuration.
- Tried forcefully converting the document to an object using
JSON.parse(JSON.stringify(data))
.