Skip to content

Instantly share code, notes, and snippets.

local MongoClient = require("luaMongo.MongoClient")
local client = MongoClient.new("mongodb://localhost:27017/")
local exampleDatabase = client:getDatabase("exampleDB")
local exampleCollection = exampleDatabase:getCollection("exampleCollection")
-- Create document to insert.
local document_to_insert = {foo = "bar"}
-- Insert document into database
exampleCollection:insert_one(document_to_insert)
db.data.find({"st" : "u103840",
"ts" : {"$gte": ISODate("1989-01-01"),
"$lt" : ISODate("1990-01-01")}})
{
"st" : "u725053",
"ts" : ISODate("2013-06-03T22:51:00Z"),
"position" : {
"type" : "Point",
"coordinates" : [
-96.4,
39.117
]
},
db.data.find({"st" : "u747940",
"ts" : ISODate("1969-07-16T12:00:00Z")})
db.data.find({"ts" : ISODate("2000-01-01T00:00:00Z")})
db.data.find ({
"presentWeatherObservation.condition" : "99"
})
db.data.aggregate ([
{ "$match" : { "airTemperature.quality" :
{ "$in" : [ "1", "5" ] } } },
{ "$group" : { "_id" : null,
"maxTemp" : { "$max" :
"$airTemperature.value" } } }
])
{ "_id" : ObjectId("5063114bd386d8fadbd6b004"),
"name" : "Brian D. Goodman",
"organizations" : ["MongoDB”],
"locations" : [
{ "type" : "work",
"address" : "229 W 34 St., 5th floor",
"city" : "New York",
"state" : "NY",
"zipcode" : "10036"
}
{ "_id" : ObjectId("5063114bd386d8fadbd6b004"),
"name" : "Brian D. Goodman",
"organizations" : ["MongoDB”],
"locations" : [
{ "type" : "work",
"address" : "229 W 34 St., 5th floor",
"city" : "New York",
"state" : "NY",
"zipcode" : "10036"
}
{"_id" : ObjectId("5063114bd386d8fadbd6b004"),
"name" : "Brian D. Goodman",
"organizations" : ["MongoDB"],
"locations" : [
{ "type" : "work",
"address" : "229 W 34 St., 5th floor",
"city" : "New York",
"state" : "NY",
"zipcode" : "10036"
}