小编Ser*_*ano的帖子

尝试在 Mongodb 中同时使用 $regex 查找多个字段

我正在尝试在我的网络应用程序中开发一个搜索器,我正在使用 mongodb ......所以......我有一个包含这些信息的文档。

{
    "_id": "458734895734",
    "name": "user",
    "ref": "1",
    "data": "fdnsfkjndjfn"
},
{
    "_id": "3332423333",
    "name": "user1",
    "ref": "2",
    "data": "dvsdvdvds"
}
Run Code Online (Sandbox Code Playgroud)

我正在使用 $regex 将搜索与我的应用程序相匹配。所以我在我的服务器 node.js 中有这个。

db.users.find({ 
    name: {'$regex': query, '$options': 'i'}
}).then((users) => {
    res.json(users);
})

        // var query, is just the pattern that i send from my web
Run Code Online (Sandbox Code Playgroud)

如您所见,我的服务器仅在“名称”字段中搜索,如何添加其他字段(如“引用”)并同时在两个字段中搜索?我已经检查了 mongodb 中的文档,但我找不到它...

mongodb node.js

6
推荐指数
1
解决办法
5592
查看次数

在 Angular 中将图像 url 转换为 base64

我正在努力尝试将给定的图像 url 转换为 base64 ......在我的情况下,我有一个带有图像路径的字符串

var imgUrl = `../../../../../assets/logoEmpresas/${empresa.logoUrl}`
Run Code Online (Sandbox Code Playgroud)

我怎样才能直接在 base64 中转换给定的图像 url?...我试过这篇文章。

以角度 2 将图像转换为 base64

但是这篇文章是从表单中获取图像...我该如何调整它?

javascript single-page-application typescript angular angular8

6
推荐指数
1
解决办法
1万
查看次数

Mongodb $addFields 如果为 null 则不输出数据

我正在努力解决一个恼人的问题。我在查询中使用聚合,我需要加入一些集合,并且输出必须是一个对象。这是我的代码...

usersModel.aggregate([
    {
        $match: { _id: ObjectId(req.params.id) }
    },
    {
        $lookup: {
            from: "agents",
            as: "agent",
            let: { "idAgent": "$agent" }, //$agent can be null
            pipeline: [
                {
                    $match: {
                        $expr: {
                            $eq: ['$_id', "$$idAgent"] 
                        },
                    }
                }
            ],
        }
    },
    { $unwind: { path: '$agent', preserveNullAndEmptyArrays: true } },
    {
        $addFields: {
            agent: "$agent", //If $agent is null, it does not output the field agent...
        }
    }

])
Run Code Online (Sandbox Code Playgroud)

如果在最后一个Stage中,字段$agent为空,则$addFields不会输出该字段。还有其他方法可以做到吗?查找后我只需要代理字段作为对象。谢谢

mongodb mongodb-query aggregation-framework

2
推荐指数
1
解决办法
2884
查看次数

如何使用 Angular 7 cli 的全日历捕捉下一个、上一个、今天的事件

我正在我的 Angular 7 应用程序中实现 fullCalendar,日历正在工作,我正在向它导入一些事件,但我试图让它更有效,我试图只带来日历需要的事件。

所以..我有一些问题。

如何在 Prev 或 Next 或 Today 按钮中获得点击事件?

如何获取当前日期?

我一直在检查文档......但只有jquery的例子......

我在这里复制我的 HTML

  <full-calendar id="calendar" *ngIf="options" #fullcalendar [editable]="true" [events]="citas"
    [header]="options.header" [locale]="options.locale" [customButtons]="options.customButtons"
    (dateClick)="dateClick($event)" [plugins]="options.plugins" (eventClick)="eventClick($event)" [eventLimit]="4">
  </full-calendar>
Run Code Online (Sandbox Code Playgroud)

还有我的 Ts

  @ViewChild('fullcalendar') fullcalendar: FullCalendarComponent;

  constructor() {
    this.options = {

      editable: true,
      header: {
        left: 'prev,next today',
        center: 'title',
        right: 'dayGridMonth, listDay'
      },
      plugins: [dayGridPlugin, listPlugin, timeGridPlugin],
      locale: esLocale,
    };

  }
Run Code Online (Sandbox Code Playgroud)

fullcalendar angular fullcalendar-4

1
推荐指数
1
解决办法
5546
查看次数