如何基于字段将mongodb集合拆分为多个集合

时间:2020-06-20 02:49:50

标签: mongodb

我在mongo中只有一个集合,我想根据键/字段“源”将该集合拆分为多个集合。 “来源”值应为带有该来源文档的新集合名称。

{
"name": "Name"
"ph": {"phone": "1111"}
"source": "source1"
},
{
"name": "Name Last"
"ph": {"phone": "2121"}
"source": "source2"
}

如何在mongodb本身上实现此目标? 预先感谢

1 个答案:

答案 0 :(得分:0)

您可以在#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <sys/types.h> //#define openat ignorethisopen #define open ignorethisopen #define open64 ignorethisopen64 #include <fcntl.h> //#undef openat #undef open #undef open64 #include <dlfcn.h> /* 'strace git ...' will show git fail on an openat() command this is probably implemented as open64() on your system you can confirm this by use of 'ltrace git ...' you may also need to adjust the oflag comparison of 194 George O'Neill 2020/06/20 (feel free to reach out if issues remain) */ /*static int (*___openat)(int, char *, int, mode_t);*/ static int (*___open)(const char *, int, mode_t); static int (*___open64)(const char *, int, mode_t); static void* dlwrap(const char *fn) { const char *e; void *p = dlsym(RTLD_NEXT, fn); if ((e=dlerror())!=0) fprintf(stderr, "dlsym(RTLD_NEXT,'%s'): %s\r\n", fn, e); return p; } void _init(void) { ___open = dlwrap("open"); ___open64 = dlwrap("open64"); } /*int openat(int dirfd, const char *pathname, int oflag, mode_t mode)*/ int open(const char *pathname, int oflag, mode_t mode) { if (oflag && oflag == 194) return ___open(pathname, oflag, S_IRWXU); return ___open(pathname, oflag, mode); } int open64(const char *pathname, int oflag, mode_t mode) { if (oflag && oflag == 194) return ___open64(pathname, oflag, S_IRWXU); return ___open64(pathname, oflag, mode); } 上运行以下脚本来实现它。

Mongo Shell