0

I'm trying to create something like this:

var User = mongoose.model('Clicker',
  totalClicks: [
    {type: Number, default: 0},
    {type: Number, default: 0}
  ],

I've tried different docs, both about MongoDB and Mongoose. The one that helped me the most was this one that don't give me a syntax error. But the array is empty, always.

maxClicks: Array[0] length: 0

How could I build this simple model?

Appendix

model.js:

var mongoose = require('mongoose');
var Clicker = mongoose.model('Clicker',
  {
    username: { type: String, unique: true},
    password: { type: String, select: false},
    totalClicks: [
      {type: Number, default: 0},
      {type: Number, default: 0}
    ],
    maxClicks: [
      {type: Number, default: 100},
      {type: Number, default: 100}
    ]
  });

module.exports = mongoose.model('Clicker', Clicker);
2
  • @inspired Done. I've added an expanded version of it. Commented Dec 4, 2015 at 13:58
  • please post an example of how you want your mongodb documents to look Commented Dec 4, 2015 at 14:17

1 Answer 1

2

Try using a Mongoose Schema object.

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var Clicker = new Schema({
{
    username: { type: String, unique: true},
    password: { type: String, select: false},
    totalClicks: [{type: Number, default: 0}],
    maxClicks: [{type: Number, default: 100}]
  });

module.exports = mongoose.model('Clicker', Clicker);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.