javascript - How use "Long" type in an MongoDB schema declaration? - Stack Overflow

I guess it's a stupid question but i would like do something like thisvar mongoose = require('

I guess it's a stupid question but i would like do something like this

var mongoose = require('mongoose');
var Long = require("long");
	
	var UserSchema = new mongoose.Schema({
		id: Long(),
		name: String,
		pleted: Long(),
		note: String,
		updated_at: { type: Date, default: Date.now },
	});

I guess it's a stupid question but i would like do something like this

var mongoose = require('mongoose');
var Long = require("long");
	
	var UserSchema = new mongoose.Schema({
		id: Long(),
		name: String,
		pleted: Long(),
		note: String,
		updated_at: { type: Date, default: Date.now },
	});

But it's not working,"cannot set 'low' property". I know that cause I do not pass arguments in the "Long" constructor but it's not working iven if I don't put the "()". I'm a bit lost with that ^^'

Sorry for my english ^^'

Share Improve this question asked Jun 19, 2016 at 7:35 ColoniseurColoniseur 851 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You should use a module specifically designed for Mongoose, like mongoose-long:

var mongoose = require('mongoose')
require('mongoose-long')(mongoose);
var Long = mongoose.Schema.Types.Long;

var UserSchema = new mongoose.Schema({
  id         : Long,
  name       : String,
  pleted  : Long,
  note       : String,
  updated_at : { type: Date, default: Date.now },
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745189454a4615795.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信