javascript Mongo关系

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Mongo关系相关的知识,希望对你有一定的参考价值。

/**
 *
 * Genres => Movies => cast & crew
 *
 * Movies have reviews:
 *  - Structure: Movies (parent) embed Reviews (child) as sub-documents
 *  - Cardinality: is one-to-few
 *
 * Movies reference cast and crew (one-to-many)
 *  - Structure: Movies (parent) reference cast and crew (child) using Ids
 *  - Cardinality is one-to-many
 *
 * Movies reference Genre
 *  - Structure: Genre (parent) is referenced by Movies (child)
 *  - Cardinality is one-to-squillions
 */

exports.genres = [
  { _id: '111111111111111111111101', name: 'SciFi' },
  { _id: '111111111111111111111102', name: 'Romance' },
  { _id: '111111111111111111111103', name: 'Adventure' },
]

exports.people = [
  { _id: '222222222222222222222201', fullname: 'Hero/Protagonist' },
  { _id: '222222222222222222222202', fullname: 'Villian/Antagonist' },
  { _id: '222222222222222222222203', fullname: 'Mentor' },
  { _id: '222222222222222222222204', fullname: 'Temptor' },
  { _id: '222222222222222222222205', fullname: 'Sidekick' },
  { _id: '222222222222222222222206', fullname: 'Skeptic' },
  { _id: '222222222222222222222207', fullname: 'Director' },
  { _id: '222222222222222222222208', fullname: 'Producer' },
  { _id: '222222222222222222222209', fullname: 'Screenwriter' },
]

exports.movies = [
  {
    id: "333333333333333333333301",
    title: 'Movie Title',
    description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
    genre: '111111111111111111111101',
    cast: ['222222222222222222222201', '222222222222222222222202', '222222222222222222222203', '222222222222222222222204', '222222222222222222222205', '222222222222222222222206'],
    crew: ['222222222222222222222207', '222222222222222222222208', '222222222222222222222209', '222222222222222222222210'],
    reviews: [
      { username: 'moviecritic', comment: 'Posuere sollicitudin aliquam ultrices sagittis orci a. Feugiat sed lectus vestibulum mattis ullamcorper velit. Odio pellentesque diam volutpat commodo sed egestas egestas fringilla. Velit egestas dui id ornare arcu odio. Molestie at elementum eu facilisis sed odio morbi. Tempor nec feugiat nisl pretium. At tempor commodo ullamcorper a lacus. Egestas dui id ornare arcu odio. Id cursus metus aliquam eleifend' },
      { username: 'scififan', comment: 'Posuere sollicitudin aliquam ultrices sagittis orci a. Feugiat sed lectus vestibulum mattis ullamcorper velit. Odio pellentesque diam volutpat commodo sed egestas egestas fringilla. Velit egestas dui id ornare arcu odio. Molestie at elementum eu facilisis sed odio morbi. Tempor nec feugiat nisl pretium. At tempor commodo ullamcorper a lacus. Egestas dui id ornare arcu odio. Id cursus metus aliquam eleifend' },
      { username: 'independent', comment: 'Posuere sollicitudin aliquam ultrices sagittis orci a. Feugiat sed lectus vestibulum mattis ullamcorper velit. Odio pellentesque diam volutpat commodo sed egestas egestas fringilla. Velit egestas dui id ornare arcu odio. Molestie at elementum eu facilisis sed odio morbi. Tempor nec feugiat nisl pretium. At tempor commodo ullamcorper a lacus. Egestas dui id ornare arcu odio. Id cursus metus aliquam eleifend' },
    ]
  },
  {
    id: "333333333333333333333302",
    title: 'Movie Title',
    description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
    genre: '111111111111111111111102',
    cast: ['222222222222222222222201', '222222222222222222222202', '222222222222222222222203', '222222222222222222222204', '222222222222222222222205', '222222222222222222222206'],
    crew: ['222222222222222222222207', '222222222222222222222208', '222222222222222222222209', '222222222222222222222210'],
    reviews: [
      { username: 'moviecritic', comment: 'Posuere sollicitudin aliquam ultrices sagittis orci a. Feugiat sed lectus vestibulum mattis ullamcorper velit. Odio pellentesque diam volutpat commodo sed egestas egestas fringilla. Velit egestas dui id ornare arcu odio. Molestie at elementum eu facilisis sed odio morbi. Tempor nec feugiat nisl pretium. At tempor commodo ullamcorper a lacus. Egestas dui id ornare arcu odio. Id cursus metus aliquam eleifend' },
      { username: 'scififan', comment: 'Posuere sollicitudin aliquam ultrices sagittis orci a. Feugiat sed lectus vestibulum mattis ullamcorper velit. Odio pellentesque diam volutpat commodo sed egestas egestas fringilla. Velit egestas dui id ornare arcu odio. Molestie at elementum eu facilisis sed odio morbi. Tempor nec feugiat nisl pretium. At tempor commodo ullamcorper a lacus. Egestas dui id ornare arcu odio. Id cursus metus aliquam eleifend' },
      { username: 'independent', comment: 'Posuere sollicitudin aliquam ultrices sagittis orci a. Feugiat sed lectus vestibulum mattis ullamcorper velit. Odio pellentesque diam volutpat commodo sed egestas egestas fringilla. Velit egestas dui id ornare arcu odio. Molestie at elementum eu facilisis sed odio morbi. Tempor nec feugiat nisl pretium. At tempor commodo ullamcorper a lacus. Egestas dui id ornare arcu odio. Id cursus metus aliquam eleifend' },
    ]
  },
  {
    id: "333333333333333333333303",
    title: 'Movie Title III',
    description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
    genre: '111111111111111111111103',
    cast: ['222222222222222222222201', '222222222222222222222202', '222222222222222222222203', '222222222222222222222204', '222222222222222222222205', '222222222222222222222206'],
    crew: ['222222222222222222222207', '222222222222222222222208', '222222222222222222222209', '222222222222222222222210'],
    reviews: [
      { username: 'moviecritic', comment: 'Posuere sollicitudin aliquam ultrices sagittis orci a. Feugiat sed lectus vestibulum mattis ullamcorper velit. Odio pellentesque diam volutpat commodo sed egestas egestas fringilla. Velit egestas dui id ornare arcu odio. Molestie at elementum eu facilisis sed odio morbi. Tempor nec feugiat nisl pretium. At tempor commodo ullamcorper a lacus. Egestas dui id ornare arcu odio. Id cursus metus aliquam eleifend' },
      { username: 'scififan', comment: 'Posuere sollicitudin aliquam ultrices sagittis orci a. Feugiat sed lectus vestibulum mattis ullamcorper velit. Odio pellentesque diam volutpat commodo sed egestas egestas fringilla. Velit egestas dui id ornare arcu odio. Molestie at elementum eu facilisis sed odio morbi. Tempor nec feugiat nisl pretium. At tempor commodo ullamcorper a lacus. Egestas dui id ornare arcu odio. Id cursus metus aliquam eleifend' },
      { username: 'independent', comment: 'Posuere sollicitudin aliquam ultrices sagittis orci a. Feugiat sed lectus vestibulum mattis ullamcorper velit. Odio pellentesque diam volutpat commodo sed egestas egestas fringilla. Velit egestas dui id ornare arcu odio. Molestie at elementum eu facilisis sed odio morbi. Tempor nec feugiat nisl pretium. At tempor commodo ullamcorper a lacus. Egestas dui id ornare arcu odio. Id cursus metus aliquam eleifend' },
    ]
  },
]

以上是关于javascript Mongo关系的主要内容,如果未能解决你的问题,请参考以下文章

7.mongo命令行运行JavaScript脚本

mongoDB--概念

mongo执行JavaScript脚本

javascript Mongo命令用于过滤引用计数

javascript Mongo Db客户端

javascript Mongo DB批量插入