# # Opens the connexion with the Mongo server.
# var client = new MongoClient("mongodb://localhost:27017/")
#
+# # Select the database.
+# var db_suffix = "NIT_TESTING_ID".environ
+# var db_name = "test_{db_suffix}"
+# var db = client.database(db_name)
+#
# # Retrieve a collection.
-# var col = client.database("test").collection("test")
+# var col = db.collection("test")
#
# # Insert a document in the collection.
# var doc = new JsonObject
end
redef fun to_s do
- var ns = native.to_native_string
- var res = ns.to_s_with_copy
+ var ns = native.to_c_string
+ var res = ns.to_s
ns.free # manual free of gc allocated CString
return res
end
# Human readable error message.
fun message: String do
var ns = native.message
- var res = ns.to_s_with_copy
+ var res = ns.to_s
ns.free
return res
end
#
# ~~~
# var client = new MongoClient("mongodb://localhost:27017/")
- # var db = client.database("test")
+ # var db_suffix = "NIT_TESTING_ID".environ
+ # var db_name = "test_{db_suffix}"
+ # var db = client.database(db_name)
# db.collection("test").insert(new JsonObject)
- # assert client.database_names.has("test")
+ # assert client.database_names.has(db_name)
# ~~~
fun database_names: Array[String] do
var res = new Array[String]
var i = 0
var name = nas[i]
while not name.address_is_null do
- res.add name.to_s_with_copy
+ res.add name.to_s
name.free
i += 1
name = nas[i]
#
# ~~~
# var client = new MongoClient("mongodb://localhost:27017/")
- # assert client.database("test").name == "test"
+ # var db_suffix = "NIT_TESTING_ID".environ
+ # var db_name = "test_{db_suffix}"
+ # var db = client.database(db_name)
+ # assert db.name == db_name
# ~~~
fun database(name: String): MongoDb do return new MongoDb(self, name)
#
# ~~~
# var client = new MongoClient("mongodb://localhost:27017/")
- # var db = client.database("test")
+ # var db_suffix = "NIT_TESTING_ID".environ
+ # var db_name = "test_{db_suffix}"
+ # var db = client.database(db_name)
# db.collection("test").insert(new JsonObject)
# assert db.collection_names.has("test")
# ~~~
var i = 0
var name = nas[i]
while not name.address_is_null do
- res.add name.to_s_with_copy
+ res.add name.to_s
name.free
i += 1
name = nas[i]
#
# ~~~
# var client = new MongoClient("mongodb://localhost:27017/")
- # var db = client.database("test")
+ # var db_suffix = "NIT_TESTING_ID".environ
+ # var db_name = "test_{db_suffix}"
+ # var db = client.database(db_name)
# var col = db.collection("test")
# assert col.name == "test"
# ~~~
#
# ~~~
# var client = new MongoClient("mongodb://localhost:27017/")
- # var db = client.database("test")
+ # var db_suffix = "NIT_TESTING_ID".environ
+ # var db_name = "test_{db_suffix}"
+ # var db = client.database(db_name)
# assert not db.has_collection("qwerty")
# ~~~
fun has_collection(name: String): Bool do
#
# ~~~
# var client = new MongoClient("mongodb://localhost:27017/")
- # var col = client.database("test").collection("test")
+ # var db_suffix = "NIT_TESTING_ID".environ
+ # var db_name = "test_{db_suffix}"
+ # var db = client.database(db_name)
+ # var col = db.collection("test")
# var doc = new JsonObject
# doc["foo"] = 10
# doc["bar"] = "bar"
#
# ~~~
# var client = new MongoClient("mongodb://localhost:27017/")
- # var col = client.database("test").collection("test")
+ # var db_suffix = "NIT_TESTING_ID".environ
+ # var db_name = "test_{db_suffix}"
+ # var db = client.database(db_name)
+ # var col = db.collection("test")
#
# var doc = new JsonObject
# doc["foo"] = 10
#
# ~~~
# var client = new MongoClient("mongodb://localhost:27017/")
- # var col = client.database("test").collection("test")
+ # var db_suffix = "NIT_TESTING_ID".environ
+ # var db_name = "test_{db_suffix}"
+ # var db = client.database(db_name)
+ # var col = db.collection("test")
# var sel = new JsonObject
# sel["foo"] = 10
# assert col.remove(sel)
#
# ~~~
# var client = new MongoClient("mongodb://localhost:27017/")
- # var col = client.database("test").collection("test")
+ # var db_suffix = "NIT_TESTING_ID".environ
+ # var db_name = "test_{db_suffix}"
+ # var db = client.database(db_name)
+ # var col = db.collection("test")
# var sel = new JsonObject
# sel["foo"] = 10
# var upd = new JsonObject
#
# ~~~
# var client = new MongoClient("mongodb://localhost:27017/")
- # var col = client.database("test").collection("test")
+ # var db_suffix = "NIT_TESTING_ID".environ
+ # var db_name = "test_{db_suffix}"
+ # var db = client.database(db_name)
+ # var col = db.collection("test")
# var query = new JsonObject
# query["foo"] = 10
# assert col.count(query) > 0
#
# ~~~
# var client = new MongoClient("mongodb://localhost:27017/")
- # var col = client.database("test").collection("test")
+ # var db_suffix = "NIT_TESTING_ID".environ
+ # var db_name = "test_{db_suffix}"
+ # var db = client.database(db_name)
+ # var col = db.collection("test")
# var query = new JsonObject
# query["foo"] = 10
# var doc = col.find(query)
#
# ~~~
# var client = new MongoClient("mongodb://localhost:27017/")
- # var col = client.database("test").collection("test")
+ # var db_suffix = "NIT_TESTING_ID".environ
+ # var db_name = "test_{db_suffix}"
+ # var db = client.database(db_name)
+ # var col = db.collection("test")
# var query = new JsonObject
# query["foo"] = 10
# assert col.find_all(query).length > 0
#
# ~~~
# var client = new MongoClient("mongodb://localhost:27017/")
- # var col = client.database("test").collection("test_aggregate")
+ # var db_suffix = "NIT_TESTING_ID".environ
+ # var db_name = "test_{db_suffix}"
+ # var db = client.database(db_name)
+ # var col = db.collection("test_aggregate")
#
# col.drop
#
#
# ~~~
# var client = new MongoClient("mongodb://localhost:27017/")
- # var col = client.database("test").collection("test")
- # assert col.stats["ns"] == "test.test"
+ # var db_suffix = "NIT_TESTING_ID".environ
+ # var db_name = "test_{db_suffix}"
+ # var db = client.database(db_name)
+ # var col = db.collection("test")
+ # assert col.stats["ns"] == "{db_name}.test"
# ~~~
fun stats: nullable JsonObject do
var bson = native.stats