Created
September 22, 2011 17:34
-
-
Save lazyval/1235419 to your computer and use it in GitHub Desktop.
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
johny@johny-X51RL:~$ mongo | |
"MongoDB shell version: 1.6.3" | |
"Thu Sep 22 21:28:06 *** warning: spider monkey build without utf8 support. consider rebuilding with utf8 support" | |
"connecting to: test" | |
var student = {name:'Alex',surname:'Astrouski', age:'20', courses:['math','databases','physics']} | |
var student2 = {name:'Some',surname:'Body', age:'200', courses:['math','databases','physics']} | |
var student3 = {name:'Hare',surname:'Krishna', age:'600', courses:['math','databases','physics']} | |
"Создал пару студентов (документов), теперь записываю в коллекцию:" | |
db.students.save(student) | |
db.students.save(student2) | |
db.students.save(student3) | |
"Какие у меня вообще есть коллекции?" | |
show collections | |
students | |
system.indexes | |
"А найду-ка я всех студентов (analog SELECT * FROM STUDENTS):" | |
db.students.find() | |
{ "_id" : ObjectId("4e7b709bde6358919e483634"), "name" : "Alex", "surname" : "Astrouski", "age" : "20", "courses" : [ "math", "databases", "physics" ] } | |
{ "_id" : ObjectId("4e7b709fde6358919e483635"), "name" : "Some", "surname" : "Body", "age" : "200", "courses" : [ "math", "databases", "physics" ] } | |
{ "_id" : ObjectId("4e7b70a1de6358919e483636"), "name" : "Hare", "surname" : "Krishna", "age" : "600", "courses" : [ "math", "databases", "physics" ] } | |
"Всех кроме саш:" | |
> db.students.find({name : {$ne : "Alex"}}) | |
{ "_id" : ObjectId("4e7b709fde6358919e483635"), "name" : "Some", "surname" : "Body", "age" : "200", "courses" : [ "math", "databases", "physics" ] } | |
{ "_id" : ObjectId("4e7b70a1de6358919e483636"), "name" : "Hare", "surname" : "Krishna", "age" : "600", "courses" : [ "math", "databases", "physics" ] } | |
"Числа записываются, кстати без кавычек -- добавлю еще одну запись:" | |
> db.students.save({name:'Somebodywithoutsurname', age:600, courses:['math','databases','physics']}) | |
"Сначала выберу тех у кого есть поле 'фамилия' потом тех у кого нет его." | |
> db.students.find({surname : { $exists : true } } ) | |
{ "_id" : ObjectId("4e7b709bde6358919e483634"), "name" : "Alex", "surname" : "Astrouski", "age" : "20", "courses" : [ "math", "databases", "physics" ] } | |
{ "_id" : ObjectId("4e7b709fde6358919e483635"), "name" : "Some", "surname" : "Body", "age" : "200", "courses" : [ "math", "databases", "physics" ] } | |
{ "_id" : ObjectId("4e7b70a1de6358919e483636"), "name" : "Hare", "surname" : "Krishna", "age" : "600", "courses" : [ "math", "databases", "physics" ] } | |
> db.students.find({surname : { $exists : false } } ) | |
{ "_id" : ObjectId("4e7b751abe26c83a1b6cadd0"), "name" : "Somebodywithoutsurname", "age" : 600, "courses" : [ "math", "databases", "physics" ] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment