These are chat archives for Automattic/mongoose

6th
Apr 2016
Manu Masson
@manu354
Apr 06 2016 06:53
Hey, I was wondering why the code on the front page of the mongoose website does not work for me
It works on my main computer
fine
but the same code
on my arduino yun just doesnt do anything, no errors.
Jan Koppe
@JanKoppe
Apr 06 2016 09:28
hi! when using the pre/post middleware on schemas to get notifications about updated documents, do they still work when the document is updated by a different client?
Albert Szekely
@pixeldublu
Apr 06 2016 09:43
sup guys
anyone know a working solution for unique entry inside a sub document schema ?
Albert Szekely
@pixeldublu
Apr 06 2016 09:54
var ListconsumersSchema = new Schema({
  Customer: {
    type: Schema.ObjectId,
    ref: 'Consumer'
    },

/// and this is inside a parent:

var EmaillistSchema = new Schema({
  consumers: [ListconsumersSchema],

  desc: {
    type: String,
i would like to make Customer unique so i will not have duplicates
tried to add unique: true, index: true or index {unique: true} but no luck
Barry
@bhutchison
Apr 06 2016 16:50
Hey guys, I am trying to create a call to an API and save the data in my mongoDB but don't know how to. If someone would like to have a chat and lend a hand that would be fantastic!
LeonineKing1199
@LeonineKing1199
Apr 06 2016 16:54
Do you know what Express is?
Christo Mitov
@christomitov
Apr 06 2016 16:55
Assuming he wants to use Nodejs for the back end
LeonineKing1199
@LeonineKing1199
Apr 06 2016 16:55
This is a Mongoose gitter...
Christo Mitov
@christomitov
Apr 06 2016 16:55
oh woops, what am i doing here
mongoose is awful.
Pier-Luc Gagnon
@Nepoxx
Apr 06 2016 16:56
Glad to have your opinion
Oh no wait. No.
Barry
@bhutchison
Apr 06 2016 16:56
Yes i know the basics. I have a small app setup with express/node backend. I just dont know how to save the data I get from the api in my db.
Christo Mitov
@christomitov
Apr 06 2016 16:56
mongo isn't a magic bullet
@bhutchison hey if you want relational schemas, just use a relational database
Pier-Luc Gagnon
@Nepoxx
Apr 06 2016 16:56
Create a model, get the data you receive, put it in a new model, then save it
tl;dr
'use strict';

const mongoose = require('mongoose');

const Schema = mongoose.Schema;

const userSchema = new Schema({
  fbid: { type: String, index: true, sparse: true }, // Facebook ID
  '@': { type: String }, // Email
  did: { type: String, index: true, sparse: true }, // Device ID
});

userSchema.set('autoIndex', true); // TODO disable this in production!

module.exports = mongoose.model('User', userSchema);
Barry
@bhutchison
Apr 06 2016 17:00
Yeah i have a schema. What I dont understand is the call I make gives me back a huge JSON file. I want to store the whole lot but I dont want to have manually create my schema to be the same as the APIs JSON layout as surely there is a way to just copy the JSON layout as my schema. I just want to grab the JSON and dump it in my DB.
Pier-Luc Gagnon
@Nepoxx
Apr 06 2016 17:01
Well remember that mongoose is "only" a schema over a schemaless database right
you could make a schema with a "mixed" type property, and set that property as the object your receive
Barry
@bhutchison
Apr 06 2016 17:02
And then just put the JSON data inside the mixed property?
Pier-Luc Gagnon
@Nepoxx
Apr 06 2016 17:02
the parsed json yea
If you intend on doing this kind of thing, you might want to use Mongo's native driver instead, Mongoose isn't helping you much here
Barry
@bhutchison
Apr 06 2016 17:06
I see. Will that allow me to just add the data as is.
Pier-Luc Gagnon
@Nepoxx
Apr 06 2016 17:06
Yes
Barry
@bhutchison
Apr 06 2016 17:07
Thank you for your help, ill take look!
Pier-Luc Gagnon
@Nepoxx
Apr 06 2016 17:09
No problem :)
Mark
@FullStackForger
Apr 06 2016 21:44
anyone here?

It kills me today. I open connection, run some tests and then in a teardown block I run code below to remove db

    expect(Mongoose.connection.db).to.exist();
    Mongoose.connection.db.dropDatabase((err, result) => {
        expect(err).to.not.exist();
        next();
    })

which returns err = null and result = true but database is still there as it was. It isn't removing it. What am I missing here?

Mark
@FullStackForger
Apr 06 2016 21:54
ok.... ignore me.... started using robomongo and didn't realize I need to manually refresh. DB is dropped as expected!