Using mongoskin.
I'm trying to do a simple update and I keep on getting the error:
Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters in hex format
Different code that I have tried:
var mongo = require('mongoskin'),
store = mongo.db(MONGO_DB_ADDESS + ':' + MONGO_DB_PORT + '/' + MONGO_DB_NAME + '?auto_reconnect=false');
session._id = 4eb5444d39e153e60b000001;
store.collection('sessions').updateById({_id : session._id}, {$set: status_obj}, {upsert : false, multi : false, safe : false}, function() { ... });
store.collection('sessions').updateById(session._id, {$set: status_obj} );
Even tried:
store.collection('sessions').update( {'_id': session._id}, {$set: {"status":'unavailable'}} );
Any help appreciated!
Thanks Fyi, I can do the update via mongo using the cli just fine:
db.sessions.update( {'_id': ObjectId('4eb5444d39e153e60b000001')}, {$set: {"status":'unavailable'}} );
Node. js is primarily used for non-blocking, event-driven servers, due to its single-threaded nature. It's used for traditional web sites and back-end API services, but was designed with real-time, push-based architectures in mind.
Node. js is not a programming language. Rather, it's a runtime environment that's used to run JavaScript outside the browser.
Node. js is sometimes misunderstood by developers as a backend framework that is exclusively used to construct servers. This is not the case; Node. js can be used on the frontend as well as the backend.
Java uses the concept of multithreading with ease, whereas Node JS does not use the concept of multi-threading like Java does. For large scale projects that involved concurrency, Java is highly recommended, whereas Node JS does not handle the thread and Java, which is the weakest point of this framework.
store.collection('sessions').updateById(session._id.toString(), {$set: status_obj} );
Adding .toString() finally resolved this for me.
Did have a similar error with Mongoose, it turned out my id was wrong, but maybe this validation function can help your:
function validate_id(id) {
return !(id !== null && (id.length != 12 && id.length != 24));
}
put this in the root of your javascript
ObjectID = require('mongoskin').ObjectID;
collection.updateById(new ObjectID(song._id), <json>, <callback>);
puts the _id you get in node into the format mongo needs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With