These are chat archives for Automattic/mongoose

Jan 2017
Michael Leanos
Jan 25 2017 00:31
Has anyone used the new ES6 Class integration feature with TypeScript? I would love to see a working example. I've been wrestling with it for a couple hours now.
Paul "Joey" Clark
Jan 25 2017 07:09

@tomspeak It looks to me like they could be non-unique, if the same choice document was pushed onto the choices array of multiple poll documents.

But that should never happen, right? So don’t worry about it.

And if it did ever happen, then I guess you have a bigger problem than just this query! So you might want to prevent it from happening somewhere else.

Each time a new choice document is created, its _id will be unique yes.

Just make sure you never add the same choice document to two polls.

If you ever clone a poll, make sure those _id don’t get cloned. I think you will get that behaviour from either poll.toObject() or from JSON.parse(JSON.stringify(poll)) but better check. ;)
Ankur sharma
Jan 25 2017 08:00

can someone check this mongodb code

                       console.log("restaurantid found")
                Yelpcontroller.update({$push: {
                        'usernames': username

Yelpcontroller.findOne({ 'restaurantid' :  id }, function(err, rid) {
                 console.log("there is error from mongodb")

                       console.log("restaurantid found")
                Yelpcontroller.update({$push: {
                        'usernames': username

                console.log("restaurant id not found")
                "restaurantid": id,
                "usernames": [username]



my else block work
but if block doesnt work
i want to update it and want to push username in usernames array
what am i doing wrong here?

var mongoose = require('mongoose');

var YelpSchema = new mongoose.Schema({


module.exports = mongoose.model('YelpSchema', YelpSchema);
thats my model
Andy Alameddine
Jan 25 2017 18:58
Does anyone have mongoosejs experience? I'm trying to grab all posts under a specific category.
const categorySchema = new mongoose.Schema({
  category: { type: String, required: true, unique: true },
  title: { type: String, required: true, unique: true }

const voteSchema = new mongoose.Schema({
  user: { type: String, required: true },
  positive: { type: Boolean, required: true }

const postSchema = new mongoose.Schema({
  user: { type: String, required: true },
  date: { type: Date, 'default': },
  blobbase64: { type: String, 'default': '' },
  description: { type: String, 'default': '' },
  votes: [voteSchema],
  category: {type: Schema.ObjectId, ref: 'Category'}

    .find({ 'category.category': categoryType })
    .exec((err, posts)= { //do stuff with posts here }
Found it! This link: under "Query conditions and other options". Thanks for the rubber duck debugging lol
      path: 'category',
      match: { 'category': categoryType }
Jan 25 2017 22:42
hi guys, I'm trying to rename a field like so, but nothing is being renamed, the new field is in the schema, too:
   Notification.update({},{$rename: { 'content': 'subject' } },
  {multi: true}, function(err, result){
    console.log("RESULT", result);