Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb 使用$set更新字段时会出现不同的值_Mongodb - Fatal编程技术网

Mongodb 使用$set更新字段时会出现不同的值

Mongodb 使用$set更新字段时会出现不同的值,mongodb,Mongodb,我试图更新数据库中的一个字段,结果非常混乱: 查看字段“zipcode” 在此之前: '' 之后 然而,我试图把不同的价值 > db.users.find() { "_id" : ObjectId("51265a5ebdbff320f02007a4"), "region_code" : "NY", "region_name" : "New York", "secret_answer2" : "Mercedes", "l_name" : "Gonzalez", "f_name" : "Za

我试图更新数据库中的一个字段,结果非常混乱:

查看字段“zipcode” 在此之前:

''
之后

然而,我试图把不同的价值

> 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 }
更新:
在JavaScript中,以0开头的数字被解释为八进制

因此,将
zipcode
值存储为字符串:

{$set: {zipcode: '02201'}}
或使用十进制值:

{$set: {zipcode: 2201}}
{$set: {zipcode: '02201'}}
{$set: {zipcode: 2201}}