I have some problems to understand nosql. I use mongodb and java and would like to create something like this: a table (persons) with a column for the name (as a row), age (as a whole), married (boolean). In regular sql, this would be easy ... but how to proceed with mongodb and java?
Ok, I know: a table in mongodb is a collection, and a column is a BSON field. I would start like this:
Mongo m = new Mongo(); DB db = m.getDB("myDatabase"); DBCollection col = db.getCollection("Persons"); BasicDBObject doc = new BasicDBObject(); doc.put("something?", "something?"); col.insert(doc);
The first 3 steps are simple. I have my collection (table), I must indicate the names (columns) of BSON, age, marriage. But how? I know the put () method, but what should I insert? And if I have a design, I would like to add a few "faces".
Any ideas? Thanks you
Golem
source share