The argument passed in must be a single line of 12 bytes

The mongoDB collection contains the following data

db.stack.find() { "_id" : "8GieRu" } 

_id is not a single line of 12 bytes,

According to the MongoDB document [ObjectID] [1], id (string) - it can be a 24-byte hexadecimal string, a 12-byte binary string, or a number.

Using Mongoose, this collection is available using this Json.

 {"_id" : new mongoose.Types.ObjectId("8GieRu")} 

and produces the following error

 /node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/objectid.js:35 throw new Error("Argument passed in must be a single String of 12 bytes or ^ Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters at new ObjectID (/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/objectid.js:35:11) [1]: http://mongodb.imtqy.com/node-mongodb-native/api-bson-generated/objectid.html 

Mongoose strictly checks ObjectId of fixed length, how can I pass Object_id using mongoose with given length

+11
mongodb mongoose
source share
5 answers

Here you mix two concepts.

While "_id" can have any value (even a subdocument such as {firstName:'Foo',lastName:'Simpson'} , "ObjectId" has a fixed set of types with some restrictions, as the error message correctly reports.

So your statement should be

 {'_id':'putWhatEverYouWantHere'} 
+13
source share

I had a problem in my router order:

 app.get('/jobs', controllers.jobs.getAllJobs); app.get('/jobs/karriere', controllers.jobs.getAllJobsXML); app.get('/jobs/:id', controllers.jobs.getJob); app.get('/jobs/:id/xml', controllers.jobs.getJobXML); 

I defined / jobs / karriere after / jobs /: id, so the application thought that โ€œkarriereโ€ is an ObjectID and returns an error. The above code is working.

+5
source share

Make sure that the method that you use in the client and server parts are the same. This error is also displayed when, for example, you send a GET on the client side and POST is required on the server side.

+1
source share

The same problem I encountered, but after RND. I found that I passed the wrong {Id: Undefined}, so there was a problem, so first check your identifier, which you passed in the URL.

  Error = "http://localhost:4000/api/deleteBook/Undefined" Right = "http://localhost:4000/api/deleteBook/5bb9e79df82c0151fc0cd5c8" 
0
source share

You pass any

 ObjectID undefinded 

If the ObjectID is not defined, this error will occur.

0
source share

All Articles