mongodb meeting with SJ

Introduction to MongoDB

 

 

A first time meetup in South Jersey at the Fire Hall in Pennsauken.   With some great support from 10gen with info sheets, stickers and pizza.

 

Notes from A. Riveria presentation:

  • Document Data Model
  • Database Technology anywhere…
  • Written in C++
  • Source Code on Github
  • Runs on most platforms
  • BSON (Binary JSON) – binary-encoded serialization
  • JSON collections
  • Embedding of objects/arrays
  • Table => Collection
  • Row => Document
  • Join => Embedded
  • Foreign Key => Reference / Link  (Object Id – autogenerated serial # for each document)
  • Partition => Shard (Shard keys across nodes)
  • Indexes on fields and collections of indexes
  • Great for lat/long
  • Geospatial queries
{} – select all where
db.users.find( {}, {username:1, firstname: 1, lastname:1, email:1}
1- true
Results (JSON):
{  username: “smith”,
    firstname: “angel”,
   lastname: “Rivera”,
   email: “a@a.com”
}

 

Insert

var insertString = {username:”smith”, value:1}

   can use quotes around the fieldnames.

 

db.users.insert(insertString);

 

(users is our collection)

 

Update

db.users.update({username: “jones”}, {$set: {email:”a@yahoo.com”}}

 

first section is where, set part does the update on the field(s)

 

MAKE SURE YOU USE $SET modifier in updates.

Only updates first record it encounters.

 

Save

Upserts.  Update or if not found then create/insert.

 

Remove/Delete

 

db.users.remove( {username:”aname”});

 

deletes a document

 

Mongo Query Operators

 

$ne (not equal)

$lt (less than)

$lte (less than equal to)

$gt

 

mongoimport

Also supports CSV, best to do JSON, the default.    Arrays in a field does not work in a CSV.

mongoimport –db sjmug -c users -v –file data.json –host localhost –port 27018 –jsonArray

 

 

 

 

Thanks to 10gen for sponsorship!

 

 

 

Leave a Reply