我试图更新数据库中的一个字段,结果非常混乱:
查看之前的“邮政编码”字段:
''
后
1153
但是我试图赋予不同的价值
> db.users.find()
{ "_id" : ObjectId("51265a5ebdbff320f02007a4"), "region_code" : "NY", "region_name" : "New York", "secret_answer2" : "Mercedes", "l_name" : "Gonzalez", "f_name" : "Zachary", "month" : 5, "country_name" : "United States", "country_code" : "US", "year" : 1970, "password" : "xxxxxx", "day" : 2, "metrocode" : "501", "city" : "New York", "secret_answer" : "xxxxxx", "zipcode" : "", "longitude" : xxxxxxx, "areacode" : "212", "ip" : "xxxxxxx", "latitude" : xxxxxx }
> db.users.update({_id: ObjectId("51265a5ebdbff320f02007a4")}, {$set: {zipcode:02201} } )
> db.users.find()
{ "_id" : ObjectId("51265a5ebdbff320f02007a4"), "region_code" : "NY", "region_name" : "New York", "secret_answer2" : "Mercedes", "l_name" : "Gonzalez", "f_name" : "Zachary", "month" : 5, "country_name" : "United States", "country_code" : "US", "year" : 1970, "password" : "xxxxxx", "day" : 2, "metrocode" : "501", "city" : "New York", "secret_answer" : "xxxxxx", "zipcode" : 1153, "longitude" : xxxxxxx, "areacode" : "212", "ip" : "xxxxxxx", "latitude" : xxxxxx }
更新:
> db.users.find({},{zipcode:1})
{ "_id" : ObjectId("51265a5ebdbff320f02007a4"), "zipcode" : 1153 }
> db.users.update({_id:ObjectId("51265a5ebdbff320f02007a4")}, {$set:{zipcode:02201}})
> db.users.find({},{zipcode:1})
{ "_id" : ObjectId("51265a5ebdbff320f02007a4"), "zipcode" : 1153 }