Last active
December 28, 2015 11:49
-
-
Save evanlucas/7496566 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
var mongoose = require('mongoose') | |
var assert = require('assert') | |
mongoose.connect('mongodb://localhost/mongotest') | |
var VideoSchema = new mongoose.Schema({ | |
title: String | |
, img: String | |
, timestamp: { type: Date, default: Date.now } | |
, viewCount: Number | |
, commentCount: Number | |
, voteCount: Number | |
}, { | |
strict: false | |
}) | |
mongoose.model('Video', VideoSchema) | |
var Video = mongoose.model('Video') | |
var a = new Video({ title: 'Test 1', commentCount: 1}) | |
, b = new Video({ title: 'Test 2', commentCount: 2}) | |
, c = new Video({ title: 'Test 3', commentCount: 3}) | |
a.save(function(err) { | |
if (err) throw err | |
b.save(function(err) { | |
if (err) throw err | |
c.save(function(err) { | |
if (err) throw err | |
Video.find({}).sort({ commentCount: -1 }).limit(3).exec(function(err, records) { | |
if (err) throw err | |
assert.equal(records[0].commentCount, 3) | |
console.log('done') | |
process.exit() | |
}) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment