This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DBCollection collection = db.getCollection("collection"); | |
| collection.save((DBObject)JSON.parse(json)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DBCollection collection = db.getCollection("collection"); | |
| DBObject dbo = (DBObject)JSON.parse(json); | |
| ObjectId oid = new ObjectId((String)dbo.get("_id")); | |
| dbo.put("_id", oid); | |
| collection.save(dbo); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class DBObjectFactory { | |
| public final static DBObject fromJson(String json) { | |
| DBObject dbo = (DBObject)JSON.parse(json); | |
| ObjectId oid = new ObjectId((String)dbo.get("_id")); | |
| dbo.put("_id", oid); | |
| return dbo; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DBCollection collection = db.getCollection("collection"); | |
| collection.save(DBObjectFactory.fromJson(json)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <env-entry> | |
| <env-entry-name>mongo.hosts</env-entry-name> | |
| <env-entry-type>java.lang.Integer</env-entry-type> | |
| <env-entry-value>2</env-entry-value> | |
| </env-entry> | |
| <env-entry> | |
| <env-entry-name>mongo.slave</env-entry-name> | |
| <env-entry-type>java.lang.Boolean</env-entry-type> | |
| <env-entry-value>true</env-entry-value> | |
| </env-entry> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private final Mongo mongo; | |
| public MongoService() throws UnknownHostException, NamingException { | |
| ArrayList<ServerAddress> addrs = new ArrayList<ServerAddress>(); | |
| int hosts = ContextUtil.getEntryAsInt("mongo.hosts"); | |
| for (int i = 0; i < hosts; i++) { | |
| String address = ContextUtil.getEntryAsString("mongo.host.address." + i); | |
| int port = ContextUtil.getEntryAsInt("mongo.host.port." + i); | |
| addrs.add(new ServerAddress(address, port)); | |
| } | |
| mongo = new Mongo(addrs); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| try { | |
| mongoService = new MongoService(); | |
| db = mongoService.getDb("myDB"); | |
| boolean authenticated = db.authenticate(ContextUtil.getEntryAsString("mongo.myDB.username"), ContextUtil.getEntryAsString("mongo.myDB.password").toCharArray()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "meh": { | |
| "feh": "what ever the user types into the form field", | |
| "bleh": "what ever the user types into the form field" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <input type="text" name="meh.feh" /> | |
| <input type="text" name="meh.bleh" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <script src="http://code.jquery.com/jquery-latest.min.js"></script> | |
| </head> | |
| <body> | |
| <h2>Create some JSON object that is nested/structured from a form</h2> | |
| <form id="form"> | |
| <input id="id" type="text" name="id" placeholder="id..." /> |
OlderNewer