javascript - Populate mongo collection for java tests -


i'm trying populate in memory mongo database tests. i'm using mongo-java-driver 2.13.3 using https://docs.mongodb.com/manual/reference/method/db.eval/ can run javascript code in memory database.

using mongoexport --out output.json flag i'm getting documents need in extended json format.

then wrap these json documents db.mycollection.insert() , try insert databse using db.eval.

but since these documents have extended json format i'm getting following error:

com.mongodb.commandfailureexception: { "serverused" : "localhost:12345" , "errmsg" : "exception: field names cannot start $ [$oid] @ src/mongo/shell/collection.js:147" , "code" : 16722 , "ok" : 0.0} 

i'm wondering if there way solve or if should use other approach achieve that.

this example of i'm trying insert:

db.keywords.insert({"_id":{"$oid":"53cd13a4e4b0d5282d586abf"},"name":"musculación","categoryid":{"$oid":"54180551d98ed9a5334110b3"},"photo":null,"created":{"$date":"2014-07-21t13:20:36.056z"},"updated":{"$date":"2016-09-27t16:17:36.692z"}}); 

i'm not sure on syntax error mongo complaining trying insert '$' reserved character field.

i tried insert document , got same error:

> db.keywords.insert({ ...     "_id": { ...         "$oid": "53cd13a4e4b0d5282d586abf" ...     }, ...     "name": "musculación", ...     "categoryid": { ...         "$oid": "54180551d98ed9a5334110b3" ...     }, ...     "photo": null, ...     "created": { ...         "$date": "2014-07-21t13:20:36.056z" ...     }, ...     "updated": { ...         "$date":"2016-09-27t16:17:36.692z" ...     } ... }) 2016-11-17t10:13:18.263-0500 e query    [thread1] error: field names cannot start $ [$oid] : dbcollection.prototype._validateforstorage@src/mongo/shell/collection.js:185:1 dbcollection.prototype._validateforstorage@src/mongo/shell/collection.js:189:13 bulk/this.insert@src/mongo/shell/bulk_api.js:646:9 dbcollection.prototype.insert@src/mongo/shell/collection.js:271:13 @(shell):1:1 

if revise syntax work - don't know if valid java driver try it:

db.keywords.insert({     "_id": objectid("53cd13a4e4b0d5282d586abf"),     "name": "musculación",     "categoryid": objectid("54180551d98ed9a5334110b3"),     "photo": null,     "created": isodate("2014-07-21t13:20:36.056z"),     "updated": isodate("2016-09-27t16:17:36.692z") }); 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -