> db.test.save({name:"TEST"});
> db.test.find().forEach(function(doc) {
... doc.lname = doc.name.toLowerCase();
... db.test.save(doc);
... });
> db.test.find();
{ "_id" : ObjectId("4f653c644b0a7cc12e0b3ea3"), "name" : "TEST",
"lname" : "test" }
> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mongodb-user/-/AqXr_MT_eo0J.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mongodb-user?hl=en.
It's still not working for me...
MongoDB shell version: 2.0.3connecting to: test> db.mydb.find().forEach(function(doc) {... doc.lname = doc.name.toLowerCase();... db.mydb.save(doc);... });Sun Mar 18 01:57:49 TypeError: doc.name.toLowerCase is not a function (shell):2>
You may want to check it before calling toLowerCase.
> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mongodb-user/-/nedbnILEeAEJ.
if(doc.name != null) doc.lname = doc.name.toLowerCase();
or make the query like this:
db.mydb.find({name:{$exists:true}});
Wes
> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mongodb-user/-/h38QYazOocgJ.
follow is testing report:
> db.blog.insert({"name":["TEST",123]})
> db.blog.find().forEach(function(doc){
... doc.name = doc.name.toLowerCase();
... db.blog.save(doc);
... })
Sun Mar 18 10:32:51 TypeError: doc.name.toLowerCase is not a function (shell):2
> db.blog.remove()
> db.blog.insert({"name":null})
> db.blog.find().forEach(function(doc){
... doc.name = doc.name.toLowerCase();
... db.blog.save(doc);
... })
Sun Mar 18 10:33:18 TypeError: doc.name has no properties (shell):2
2012/3/18 Wes Freeman <freem...@gmail.com>:
--
红颜弹指老,刹那芳华!
any idea?
2012/3/18 H.J <shiy...@gmail.com>:
--
红颜弹指老,刹那芳华!
This works, however:
> db.test.find().forEach(function(doc) {
... if(doc.name != null && typeof doc.name == "string") doc.lname =
doc.name.toLowerCase();
... db.test.save(doc);
... });
Wes