2011-08-11 60 views
0

我有這個JSONMongoimport UPSERT問題

{ 
_id :  10000000042, 
OtherID: 10000000043, 
} 

C文件:\ mongodb的-Win32的i386-1.9.0 \ BIN> mongoimport.exe --host本地主機--db CRM - 收集TST --file C:\ TEMP \ tst3.txt --jsonArray --upsert --upsertFields OtherID

連接到:本地主機進口1個對象

在蒙戈控制檯:

> db.tst.find(); 
    { "_id" : NumberLong("10000000042"), "OtherID" : NumberLong("10000000043") } 

> db.tst.getIndexes() 
[ 
     { 
       "name" : "_id_", 
       "ns" : "crm.tst", 
       "key" : { 
         "_id" : 1 
       }, 
       "v" : 0 
     }, 
     { 
       "_id" : ObjectId("4e435d7a296ca66d8f50b0e0"), 
       "ns" : "crm.tst", 
       "key" : { 
         "OtherID" : 1 
       }, 
       "name" : "OtherID_1", 
       "v" : 0 
     } 
] 

然後我更新我的JSON:

{ 
_id :  10000000042, 
OtherID: 10000000044, 
} 

和mongoimport再次

運行在控制檯:

> db.tst.find(); 
    { "_id" : NumberLong("10000000042"), "OtherID" :NumberLong("10000000043") } 

OtherID字段不更新。

我的手壞了?

回答

3

刪除「upsertFields」參數,你是黃金。這不是你在這裏要做的事情所需要的。

+0

Remon,謝謝。我早些時候嘗試過,但它不起作用。但並非一切都好,它的工作原理! – Igorekk

+0

不客氣;) –