我创建了一个“品牌”集合,然后collation: { locale: "en", strength: 2}
在“标题”字段上添加了一个索引。但是当我尝试使用此排序规则查询它时,它无法按预期工作:
const query = brand => mongodb.db("my-db").collection("brands")
.aggregate([
{ $match: { title: brand } },
{ $project: { _id: 0, total: 1, categories: { $slice: [ "$categories", 5 ] }, tags: { $slice: [ "$tags", 5 ] } } }
], { collation: { locale: 'en', strength: 2 } })
.asArray();
Run Code Online (Sandbox Code Playgroud)
所以调用brand('Test')
会给出结果,但brand('test')
给出一个空列表。
当我使用 Atlas Aggregation Builder 尝试相同的查询时,两个查询都会给出相同的(非空)结果。有任何想法吗?
我是一个尝试 MongoDB-atlas 免费套餐的新手。我有一个名为 - “mongoCluster”的集群。在它下面,我有一个数据库 - “testdb”,在它下面有一个集合 - “testcollection”。该集合包含文档。从我的 java 应用程序中插入和读取工作正常。
现在我正在尝试在 MongoDB atlas 中创建一个新的计划触发器。但当我运行以下两行时,出现以下错误。对于任何其他 mongo 查询(如删除、更新和插入)也是如此。
代码:
exports = function() {
const collection=context.services.get("mongoCluster").db("testdb").collection("testcollection");
collection.insertOne({"a": "b"});
// const doc = collection.findOne();
};
Run Code Online (Sandbox Code Playgroud)
错误:
> ran on Mon Nov 16 2020 18:52:52 GMT-0800 (Pacific Standard Time)
> took 272.591178ms
> error:
TypeError: Cannot access member 'db' of undefined
> trace:
TypeError: Cannot access member 'db' of undefined
at exports (function.js:24:24)
at apply (<native code>)
at function_wrapper.js:3:1
at <anonymous>:8:1
Run Code Online (Sandbox Code Playgroud)
查看错误,要么服务名称不正确(“未定义错误”),要么我缺少服务/数据库/集合的一些权限(“匿名:8:1 错误”)。
我在 …
我目前正在尝试使用社交媒体登录,并意识到这些登录信息的交付方式有些奇怪,这是因为我的工作场所与大多数办公室一样,将 3rd 方 cookie 作为安全策略阻止。
Google Firebase 身份验证使用 3rd 方 cookie,因此如果我尝试使用 Firebase,我将被重定向到 Google 页面(如预期)但是当我在登录后被重定向回原始网页时(并且 Firebase 尝试设置 cookie) , 我收到一条错误消息This browser is not supported or 3rd party cookies and data may be disabled.
但是,MongoDB Stitch以某种方式工作,即使禁用了 3rd 方 cookie,我也可以实际登录。我似乎真的无法理解为什么会这样,但我希望这里有人可以对此有所了解。如果有帮助,MongoDB Stitch 会要求您在 Google 控制台中将其设置https://stitch.mongodb.com
为 Origin URI 和https://stitch.mongodb.com/api/client/v2.0/auth/callback
Authorized Redirect URI - 而您必须在 MongoDB 控制台中设置自己的网站 URI,我认为这可能是不同之处?
无论如何,MongoDB Stitch 的文档严重不足(由于它仍处于公开测试阶段),所以如果可能的话,我真的很想采用 Google Firebase 的方式。
cookies google-authentication oauth-2.0 firebase-authentication mongodb-stitch
想在 NextJS 应用程序中使用 Stitch(基本上是同构反应)。通常,您可以在初始请求的标头中传递 JWT 或会话令牌,如果用户已经有会话,您可以立即加载他们的所有数据并在服务器上对应用程序进行水化。
使用 Google Firebase Auth,您甚至可以通过在请求中传递令牌并使用该令牌在服务器端收集用户来实现此目的。
不过,我不确定这将如何与 Stitch 一起使用。文档说 Stitch 创建了一个存储在本地存储中的令牌。有没有办法将它传递给服务器以用于对服务器上的用户进行身份验证?
此外,用于缝合的 SDK 不是同构的。有一个服务器和一个浏览器 SDK。只能在浏览器中处理用户会话吗?这似乎很难用于服务器渲染的应用程序。我错过了什么吗?
我正在使用MongoDB 的 Stitch 平台。我想在数据库中存储与该值关联的avalue
和 a count
。现在value
可能不是第一次出现,所以我想插入value
with count = 1
。我可以使用update()
更新计数的现有值,$inc
或者我可以使用upsert()
在数据库中添加值。现在,问题是,我有一个map
我的值和计数,我想一次插入(更新/更新)。我不想给网络带来负担。我正在使用一次insertMany()
插入map
,但它显然不会更新值。
那么有可能这样做吗?
PS我正在使用javascript。
我已经能够使用MongoDB Stitch进行注册和登录,但是找不到如何更新用户数据。我尝试对db.users或db.user进行查询,但这些查询不存在。
有没有更新用户的方法?
我在 MongoDB 中创建 Stitch 函数并得到未定义的结果而不是双倍。
我正在开发一个 iOS 应用程序,使用 MongoDB 数据库。我正在创建缝合函数,并使用 callFunction(withName:withArgs:_:) 方法。我编写了一个函数来计算平均早晨值。我想将早上的值返回给应用程序。这是下面的代码。
exports = function(DAY,MONTH){
var total = 0.0;
var count = 0.0;
var morning = 0.0;
var collection = context.services.get("mongodb-atlas").db("database_name").collection("collection_name");
var docs = collection.find({month: { $eq: MONTH },
day: { $eq: DAY },
hour: { $gte: 8 },
hour: { $lt: 13 }
}).toArray().then((data) => {
data.forEach((el) =>{
total = total + el.value;
count = count + 1.0;
});
morning = total/count;
console.log("morning");
console.log(morning);
return {morning};
})
.catch((error) => …
Run Code Online (Sandbox Code Playgroud) 我正在使用 mongodb 的缝合后端来运行一个应用程序,当我尝试以匿名用户身份登录时,它会抛出此错误:
匿名登录失败:{ StitchError:
/*****/*****/*****/****/node_modules/mongodb-stitch/dist不支持通过“匿名用户”进行身份验证/node/common.js:29:19
at
process._tickCallback (internal/process/next_tick.js:160:7)
name: 'StitchError',
response:
Body {
url: '*****',
status: 401,
statusText: 'Unauthorized',
headers: Headers { _headers: [Object] },
ok: false,
body:
Gunzip {
_readableState: [ReadableState],
readable: false,
domain: null,
_events: [Object],
_eventsCount:4,
_maxListeners:未定义,
_writableState:[WritableState],
可写:假,
allowHalfOpen:真,
_transformState:本发明的课题,
bytesRead:81,
_handle:空,
_hadError:假,
_writeState:[Uint32Array],
_outBuffer:,
_outOffset : 57,
_level: -1,
_strategy: 0,
_chunkSize: 16384,
_flushFlag: 0,
_scheduledFlushFlag: 0,
_origFlushFlag: 0,
_finishFlushFlag: 4,
_info: undefined },
bodyUsed: true,
size: 0,
timeout: 0,
_raw:
[ ],
_abort: …
MongoDB Stitch:iOS SDK - 注册问题:
我试过这个:
let stitchClient = StitchClient(appId: "<my-app-id>")
stitchClient.register(email: email, password: password).then({ () in
print("Signed up here")
})
.catch({ (err) in
print("Sign up fu**ed up: \(err)")
})
Run Code Online (Sandbox Code Playgroud)
总是得到这个:
responseParsingFailed("没有收到服务器的有效数据").
当我点击注册网址时(https://stitch.mongodb.com/api/client/v2.0/app/my-app-name/auth/providers/local-userpass/register/)
使用这些参数({"email":"what@mailinator.com","password":"password"})作为正文的一部分,
服务器返回:
404页面不存在
我做了一些不期望的事情吗?
我可以在mongoDB Stitch 文档中看到limit选项,但是找不到如何跳过分页记录的方法。
没有什么比在简单的任务上失败更令人沮丧的了。
我正在关注:https : //docs.mongodb.com/stitch/getting-started/first-stitch-app/ - 我得到了 setp 9 - 这应该清除权限规则,所以任何人都可以查看我的职位;但是,我仍然收到权限错误。
Uncaught (in promise) Error: no rule exists for namespace 'blog.comments'
at client.js:343
at <anonymous>
Run Code Online (Sandbox Code Playgroud)
这是整个代码 - 但我怀疑错误出在针迹设置方面。是的 - 我已经用我的应用程序 ID 替换了“your-app-id”...我确实清除了过滤器,并且我确实将 READ 权限更改为 {}...
<html>
<head>
<script src="https://s3.amazonaws.com/stitch-sdks/js/library/v2/stable/stitch.min.js"></script>
<script>
const client = new stitch.StitchClient('<your-app-id>');
const db = client.service('mongodb', 'mongodb-atlas').db('blog');
function displayComments() {
db.collection('comments').find({}).execute().then(docs => {
var html = docs.map(c => '<div>' + c.comment + '</div>').join('');
document.getElementById('comments').innerHTML = html;
});
}
function displayCommentsOnLoad() {
client.login().then(displayComments)
}
function addComment() {
var …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在Angular 7应用程序中添加与MongoDB Stich的连接性,但应用程序失败并出现以下错误:
bson.browser.esm.js:453未捕获的ReferenceError:未定义全局
我正在使用Angular 7.2.12并安装了mongodb-stitch-browser-sdk v 4.3.2
我正在使用MongoDB网站上DB Stitch应用程序客户端设置下的代码。
import { Component, OnInit } from '@angular/core';
import { Stitch, RemoteMongoClient, AnonymousCredential} from 'mongodb-stitch-browser-sdk'
@Component({
selector: 'app-alfabetisk',
templateUrl: './alfabetisk.component.html',
styleUrls: ['./alfabetisk.component.css']
})
export class AlfabetiskComponent implements OnInit {
constructor() { }
ngOnInit() {
const client = Stitch.initializeDefaultAppClient('app-id');
}
}
Run Code Online (Sandbox Code Playgroud)
该应用程序在ngOnInit()中失败,并显示以下错误:
bson.browser.esm.js:453未捕获的ReferenceError:在webpack_require(引导程序: 78)位于Module ../ node_modules / mongodb-stitch-core-sdk / dist / esm / index.js(index.js:1)位于webpack_require(bootstrap:78)位于Module ../ node_modules / mongodb-stitch-browser -core / dist / esm / index.js(index.js:1)在webpack_require(bootstrap:78)在Module ../ …
mongodb-stitch ×12
mongodb ×10
javascript ×3
angular ×1
asynchronous ×1
cookies ×1
ios ×1
next.js ×1
oauth-2.0 ×1
sdk ×1
swift ×1