{
"_id" : ObjectId("565d53893454a8520659be84"),
"customer_name" : "john",
"customer_gender" : "male",
"customer_age" : "20",
"customer_uuid" : "1231231232334342123123",
"customer_date_joined" : ISODate("2015-12-01T08:00:09.739Z"),
"customer_claimed_deals" : [ ],
"customer_preferences" : [
"Dim sum"
],
"__v" : 0,
"ban_status" : false
}
this.banCustomer = function(req, res, next){ var data = req.body; Customer.update({"_id":data.customer_id},{$set:{"ban_status":true}},function(err,customers){ if(err){ res.sendStatus(500); } return res.sendStatus(200); }); };
console.log(customers);
{ ok: 0, n: 0, nModified: 0 }
Double check that data.customer._id is a mongoid type, and not a string.
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/7aab8308-6f34-4399-9e9a-5c64ba7bc32c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Im not sure what your language is there, but in php we would just do
new MongoId($data->customer->_id).
In javascript (mongo shell) it would be
ObjectId(data.customer._id)
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/134b8c04-0a4f-4b74-b721-a22e15d9b61c%40googlegroups.com.
Hi John,
I believe Tim is correct in concluding that the reason the update failed is due to the datatype of the _id field. Although commonly represented as a 24-digit hex string for display purposes, an ObjectID is actually stored as a 12-byte value.
Assuming you’re using the official Node driver and the type of data.customer_id is a String, the code you provided could be modified as such:
var ObjectID = require('mongodb').ObjectID;
...
Customer.update(
{"_id":new ObjectID(data.customer_id)}
,{$set:{"ban_status":true}},function(err,customers){
...
Also, please note that the use of update() is deprecated in the official Node 2.0 driver in favor of updateOne() and updateMany().
For more information see the Node.js driver documentation.
If you’re still having difficulty, can you please provide a code snippet and let us know the specific version of the Node.js driver that you are using.
Best regards,
Kevin