Skip to content

Instantly share code, notes, and snippets.

@cranic
Created December 19, 2013 16:01
Show Gist options
  • Select an option

  • Save cranic/8041632 to your computer and use it in GitHub Desktop.

Select an option

Save cranic/8041632 to your computer and use it in GitHub Desktop.
var mongoose = require('mongoose')
, mongoosastic = require('mongoosastic')
, Schema = mongoose.Schema;
mongoose.createConnection('mongodb://localhost/searchMongo', function(err, dd){
if(err)
console.log(err);
else
console.log('conectado!');
var UserSchema = new Schema({
name: {type:String, es_indexed:true}
, email: String
, city: String
});
UserSchema.plugin(mongoosastic);
var User = mongoose.model('User', UserSchema);
var novo = {
name: 'teste'
, email: 'ddd'
, city: 'guaratingueta'
};
var novoUser = new User();
novoUser.name = novo.name;
novoUser.email = novo.email;
novoUser.city = novo.city;
novoUser.save(function(err, dado){
if(err)
console.log(err);
else
console.log(dado);
});
User.search({query:"teste"}, function(err, results) {
if(err)
console.log(err);
else
console.log(results)
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment