Browse files

fix to examples/queries

  • Loading branch information...
1 parent 417d05a commit 1cbcc33ab240d2284584a99ab4eb53bdb2cd707e @vdemedes committed Mar 29, 2012
Showing with 43 additions and 68 deletions.
  1. +1 −1 examples/queries.coffee
  2. +42 −22 examples/queries.js
  3. +0 −45 tests/mongorito.test.coffee
View
2 examples/queries.coffee
@@ -22,7 +22,7 @@ Post.find limit: 5, skip: 2, (err, posts) -> # getting only 5 posts, skipping fi
Post.find author: 'Drew', limit: 5, skip: 2, (err, posts) -> # getting only 5 posts, skipping first 2, with author = Drew
-Post.find sort: _id: -1 (err, posts) -> # getting posts, sorted by _id
+Post.find sort: _id: -1, (err, posts) -> # getting posts, sorted by _id
Post.find limit: 5, sort: _id: -1, (err, posts) -> # getting first 5 posts, sorted by _id
View
64 examples/queries.js
@@ -2,7 +2,7 @@ var Mongorito, Post;
Mongorito = require('../lib/mongorito');
-Mongorito.connect('databaseName', ['127.0.0.1:27017']);
+Mongorito.connect(['mongo://127.0.0.1:27017/databaseName']);
Post = (function() {
@@ -30,32 +30,52 @@ Post.find({
title: 'Nice title!'
}, function(err, posts) {});
-Post.findWithLimit(5, function(err, posts) {});
+Post.find({
+ limit: 5
+}, function(err, posts) {});
-Post.findWithLimit({
- author: 'Drew'
-}, 5, function(err, posts) {});
+Post.find({
+ author: 'Drew',
+ limit: 5
+}, function(err, posts) {});
-Post.findWithLimit(5, 2, function(err, posts) {});
+Post.find({
+ limit: 5,
+ skip: 2
+}, function(err, posts) {});
-Post.findWithLimit({
- author: 'Drew'
-}, 5, 2, function(err, posts) {});
+Post.find({
+ author: 'Drew',
+ limit: 5,
+ skip: 2
+}, function(err, posts) {});
-Post.findWithOrder({
- _id: -1
+Post.find({
+ sort: {
+ _id: -1
+ }
}, function(err, posts) {});
-Post.findWithOrderAndLimit({
- _id: -1
-}, 5, function(err, posts) {});
+Post.find({
+ limit: 5,
+ sort: {
+ _id: -1
+ }
+}, function(err, posts) {});
-Post.findWithOrderAndLimit({
- _id: -1
-}, 5, 2, function(err, posts) {});
+Post.find({
+ limit: 5,
+ skip: 2,
+ sort: {
+ _id: -1
+ }
+}, function(err, posts) {});
-Post.findWithOrderAndLimit({
- author: 'Drew'
-}, {
- _id: -1
-}, 5, 2, function(err, posts) {});
+Post.find({
+ limit: 5,
+ skip: 2,
+ author: 'Drew',
+ sort: {
+ _id: -1
+ }
+}, function(err, posts) {});
View
45 tests/mongorito.test.coffee
@@ -1,45 +0,0 @@
-Mongorito = require '../lib/mongorito'
-
-Mongorito.connect 'mongorito', ['127.0.0.1:27017']
-Mongorito.cache ['127.0.0.1:11211']
-
-require 'should'
-
-class Post
- constructor: ->
- super 'posts'
-
-Post = Mongorito.bake Post
-
-describe 'Mongorito', ->
- describe 'creating new record', ->
- it 'should create new record in "posts" collection', (done) ->
- post = new Post
- post.title = 'Very nice post!'
- post.author = 'Vadim'
- post.save ->
- Post.find (err, posts) ->
- posts.length.should.equal 1
- do done
-
- describe 'editing record', ->
- it 'should save edited version of the post', (done) ->
- Post.find (err, posts) ->
- post = posts[0]
- post.title = 'Edited title!'
- post.save ->
- do done
-
- describe 'getting record', ->
- it 'should fetch just edited post', (done) ->
- Post.find (err, posts) ->
- posts[0].title.should.equal 'Edited title!'
- do done
-
- describe 'deleting record', ->
- it 'should remove post', (done) ->
- Post.find (err, posts) ->
- posts[0].remove ->
- Post.find (err, posts) ->
- posts.length.should.equal 0
- do done

0 comments on commit 1cbcc33

Please sign in to comment.