MongoDB Java Driver: How to insert into any collection from Java Driver -


i have client facing application function takes in 2 arguments strings, arg1 collection, arg 2 function, arg 2 hash of object

so in java have

foo(string collection, string object): 

/*and have db object mongodb driver collection want insert "users" */

mongoclient mongoclient = new mongoclient( "localhost" ); db db = mongoclient.getdb("mydb"); 

now here having trouble

db.runcommand({insert : collection (? can this),                ????}) <- dont know how right , append object 

i did bunch of searching before hand , lot of examples found had predefined collection need abstract this.

any extremely useful, thank you.

update:

i not looking coll.find() java method. want visualize someones mongodb data better output shell provides. looking general db.runcommand(string) can take in insert/find/findone() whatever passed in string. can collection names using runcommand understand on basic level, cannot apply specific commands user defined collection.

sample:

dbcollection coll = db.getcollection("collection");  /* {    "name" : "mongodb",    "type" : "database",    "count" : 1,    "info" : {                x : 203,                y : 102              } } */  basicdbobject doc = new basicdbobject("name", "mongodb").                               append("type", "database").                               append("count", 1).                               append("info", new basicdbobject("x", 203).append("y", 102));  coll.insert(doc); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -