mongoimport --mode merge --typ csv --collection not working

时间:2018-04-05 00:13:25

标签: mongodb mongo-shell mongoimport

尝试导入以下csv:

_id,receiver,month,accrualMonth,paymentData.bankCode,operation
573378aef3af68090023da7d,547517955021020200599440,2016-05,2016-04,41,Manual

当我在mongo shell mongo版本3.4.5中运行时

mongoimport --db mean-dev --mode=merge --collection fulfilledpayments  --type csv --headerline --file ~/Downloads/\Import.csv -vvvv

它会返回以下日志,但它并不真正导入:

2018-04-04T20:51:25.331-0300    using upsert fields: [_id]
2018-04-04T20:51:25.332-0300    using 0 decoding workers
2018-04-04T20:51:25.332-0300    using 1 insert workers
2018-04-04T20:51:25.332-0300    will listen for SIGTERM, SIGINT, and SIGKILL
2018-04-04T20:51:25.360-0300    filesize: 139 bytes
2018-04-04T20:51:25.361-0300    using fields: _id,receiver,month,accrualMonth,paymentData.bankCode,operation
2018-04-04T20:51:25.381-0300    connected to: localhost
2018-04-04T20:51:25.381-0300    ns: mean-dev.fulfilledpayments
2018-04-04T20:51:25.381-0300    connected to node type: standalone
2018-04-04T20:51:25.381-0300    standalone server: setting write concern w to 1
2018-04-04T20:51:25.381-0300    using write concern: w='1', j=false, fsync=false, wtimeout=0
2018-04-04T20:51:25.381-0300    standalone server: setting write concern w to 1
2018-04-04T20:51:25.381-0300    using write concern: w='1', j=false, fsync=false, wtimeout=0
2018-04-04T20:51:25.382-0300    got line: [573378aef3af68090023da7d 547517955021020200599440 2016-05 2016-04 41 Manual]
2018-04-04T20:51:25.384-0300    imported 1 document

但是没有任何东西真正导入到数据库中,这仍然不受影响:

{
    "_id" : ObjectId("573378aef3af68090023da7d"),
    "creator" : "547517955021020200599440",
    "amountTransferred" : 101.79,
    "externalId" : "61fa09",
    "date" : ISODate("2016-05-06T16:00:00.000-03:00"),
    "payments" : [ 
        ObjectId("559363f127c09e0900b679dd"), 
        ObjectId("55bc4c9170b99e090093e2a8"), 
        ObjectId("55e5175a3b2a8e090040d4cd"), 
        ObjectId("560cab8bad3c6a0900275f5a"), 
        ObjectId("563cc8d3f2db060900a8ba81"), 
        ObjectId("5661033e57d24c090035b191"), 
        ObjectId("568eac27eaa71c090074d5b0"), 
        ObjectId("56b2e691ced93a0900408267"), 
        ObjectId("56d905cb4c830809007e8355"), 
        ObjectId("56fee8063cdd4d0900776fa9"), 
        ObjectId("5732732e5d237d09008c57e2")
    ],
    "__v" : 0
}

如果我将--collection fulfilledpayments参数关闭,它会导入到新的集合,但当然不需要合并模式,因为它不包含要匹配的_id。

1 个答案:

答案 0 :(得分:0)

也许您应该将_id放在ObjectId中,例如:

_id,receiver,month,accrualMonth,paymentData.bankCode,operation
ObjectID(573378aef3af68090023da7d),547517955021020200599440,2016-05,2016-04,41,Manual

https://docs.mongodb.com/manual/reference/program/mongoimport/#ex-mongoimport-merge