mongodb.js 949 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * example:
  3. var mongo = require('../libs/mongodb');
  4. exports.userModel = mongo.user;
  5. exports.poiModel = mongo.poi;
  6. mongo.initDB();
  7. var userInfo = new exports.userModel;
  8. userInfo._id = 'art_userid_'+user.uid;
  9. userInfo.timeline=this.timestamp();
  10. userInfo.loc = [user.longitude,user.latitude];
  11. userInfo.save();
  12. */
  13. 'use strict';
  14. /**
  15. * Module dependencies.
  16. */
  17. var mongoose = require('mongoose');
  18. var Schema = mongoose.Schema;
  19. var C = require('../config');
  20. //var ynDB = mongoose.connection;
  21. var poiSchema = new Schema({
  22. _id: String,
  23. poiName : String,
  24. tagid: Number,
  25. loc : {
  26. type: [Number],
  27. index: '2d'
  28. }
  29. });
  30. var userSchema = new Schema({
  31. _id: String,
  32. timeline:Number,
  33. loc : {
  34. type: [Number],
  35. index: '2d'
  36. }
  37. });
  38. exports.poi = mongoose.model('poi',poiSchema);
  39. exports.user = mongoose.model('user',userSchema);
  40. exports.initDB = function(){
  41. mongoose.connect(C.mongo.uri, C.mongo.options);
  42. };