我無法訪問mongodb機器。所以我不能運行mongoexport命令。因此,我試圖讓我的查詢輸出爲CSV格式。roboMongo導出爲csv輸出顯示bson
查詢在RoboMongo
var cursor = db.getCollection('fineProduct').find
(
{"inbuilt.bookingReference" : { $exists : true }} ,
{"_id":1,
"Reference":1,
"inbuilt.bookingReference":1,
"inbuilt.status":1,
"purchase.fineSegments.departureDatetime":1,
"purchase.fineSegments.arrivalDatetime":1,
"purchase.fineSegments.product.carriage.type":1,
"purchase.fineSegments.pricing.amount":1,
"purchase.fineSegments.pricing.currency":1
}
)
while (cursor.hasNext()) {
var record = cursor.next();
var output = "";
for (var i in record) {
output += record[i] + ",";
};
output = output.substring(0, output.length - 1);
print(output);
}
查找查詢輸出(以JSON) - 這裏只提供
{
"_id" : 10,
"inbuilt" : {
"status" : "VALIDATED",
"bookingReference" : "2015900051789"
},
"purchase" : [
{
"fineSegments" : [
{
"departureDatetime" : ISODate("2015-09-30T18:35:00.000Z"),
"arrivalDatetime" : ISODate("2015-09-30T19:17:00.000Z"),
"product" : {
"carriage" : {
"type" : "House"
}
},
"pricing" : {
"amount" : "339.00",
"currency" : "INR"
}
}
]
}
],
"vendorReference" : "FIRE"
}
輸出(在CSV)1列
10,[object BSON],[object BSON],FIRE
12,[object BSON],[object BSON],FIRE
13,[object BSON],[object BSON],FIRE
14,[object BSON],[object BSON],FIRE
15,[object BSON],[object BSON],FIRE
17,[object BSON],[object BSON],FIRE
18,[object BSON],[object BSON],FIRE
19,[object BSON],[object BSON],FIRE
20,[object BSON],[object BSON],FIRE
有沒有什麼辦法讓[對象BSON]字符串?
Mongo db version 3.0.8 | robomongo版本Robomongo 0.9.0-RC8
mongoexport作品通過網絡。如果你可以用robomongo連接到mongodb,你應該可以通過mongoexport連接到它。 –
我無法訪問安裝的機器(ssh進入盒子)!但是,robomongo可以通過端口訪問數據庫,因爲它是由網絡團隊啓用IP:PORT的。) – smilyface
您不需要ssh。在運行robomongo的同一臺機器上運行mongoexport,並使用相同的ip:port選項。 –