个人案例
- 云函数Aggregate.geoNear的minDistance和maxDistance不起作用?
云函数Aggregate.geoNear的minDistance和maxDistance不起作用,超出了maxDistance的结果还是被查询出来了。 app.router("NearShops", async (ctx, next) => { const result = await db.collection('ShopAdmin') .aggregate() .geoNear({ spherical: true, near: db.Geo.Point(event.longitude, event.latitude), query: { adminType: _.in(['Super', 'General']), app: _.elemMatch({ type: _.eq('Recommend'), isEnd: _.eq(1), }) }, minDistance: 1000, maxDistance: 5000, distanceField: 'distance', distanceMultiplier: 6378137, key: 'location', includeLocs: 'location', }).lookup({ from: 'Shop', let: { shopId: '$shopId', }, pipeline: $.pipeline() .match(_.expr($.eq(['$_id', '$$shopId']))) .project({ _id: 0, app: 0 }).done(), as: 'shopInfo', }).replaceRoot({ newRoot: $.mergeObjects([$.arrayElemAt(['$shopInfo', 0]), '$$ROOT']) }).project({ shopInfo: 0 }).lookup({ from: 'Goods', let: { goods: '$goods', }, pipeline: $.pipeline() .match(_.expr($.in(['$_id', '$$goods']))) .sample({ size: 2 }).project({ imgUrl: 1, }).done(), as: 'partGoods', }).end(); ctx.body = { data: result.list } });
2021-11-26 - 构建npm包时报错(SyntaxError: Unexpected token )?
npm install p-limit安装好后,在构建npm时报错SyntaxError: Unexpected token (28:10) p-limit: index.js import Queue from 'yocto-queue'; export default function pLimit (concurrency) { if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) { throw new TypeError('Expected `concurrency` to be a number from 1 and up'); } const queue = new Queue(); let activeCount = 0; const next = () => { activeCount--; if (queue.size > 0) { queue.dequeue()(); } }; const run = async (fn, resolve, args) => { activeCount++; const result = (async () => fn(...args))(); resolve(result); try { await result; } catch { } next(); }; const enqueue = (fn, resolve, args) => { queue.enqueue(run.bind(undefined, fn, resolve, args)); (async () => { // This function needs to wait until the next microtask before comparing // `activeCount` to `concurrency`, because `activeCount` is updated asynchronously // when the run function is dequeued and called. The comparison in the if-statement // needs to happen asynchronously as well to get an up-to-date value for `activeCount`. await Promise.resolve(); if (activeCount < concurrency && queue.size > 0) { queue.dequeue()(); } })(); }; const generator = (fn, ...args) => new Promise(resolve => { enqueue(fn, resolve, args); }); Object.defineProperties(generator, { activeCount: { get: () => activeCount, }, pendingCount: { get: () => queue.size, }, clearQueue: { value: () => { queue.clear(); }, }, }); return generator; } yocto-queue: index.js /* How it works: `this.#head` is an instance of `Node` which keeps track of its current value and nests another instance of `Node` that keeps the value that comes after it. When a value is provided to `.enqueue()`, the code needs to iterate through `this.#head`, going deeper and deeper to find the last value. However, iterating through every single item is slow. This problem is solved by saving a reference to the last value as `this.#tail` so that it can reference it to add a new value. */ class Node { value; next; constructor(value) { this.value = value; } } export default class Queue { #head; #tail; #size; constructor() { this.clear(); } enqueue(value) { const node = new Node(value); if (this.#head) { this.#tail.next = node; this.#tail = node; } else { this.#head = node; this.#tail = node; } this.#size++; } dequeue() { const current = this.#head; if (!current) { return; } this.#head = this.#head.next; this.#size--; return current.value; } clear() { this.#head = undefined; this.#tail = undefined; this.#size = 0; } get size() { return this.#size; } * [Symbol.iterator]() { let current = this.#head; while (current) { yield current.value; current = current.next; } } }
2021-11-25 - 请问有人在小程序上用过“p-Limit”来做并发限制吗?
小程序优化时提示并发超限,现在想用p-Limit来做并发限制,引入后报错。 [图片] https://www.npmjs.com/package/p-limit
2021-11-24 - npm audit fix --force修复失败?
更新wx-server-sdk时提示漏洞,需要修复。 但是通过“npm audit fix --force”命令却无法修复 [图片]
2021-11-24 - 小程序优化,存在短时间内发起太多的请求?
在Audits检测时,提示短时间内发起了 11 次请求,问: 是否可以将请求写到onShow或onReady?请求合并的方法?onLoad: async function (options) { this._queryPathType(options, pathType); this._queryGroupInfo(isTicket); if (!isLogin) { this._fetchClockInRecord(); this._fetchLuckers(); this._fetchLinkShop(); this._fetchAdviser(); this._fetchFlockBroadcast(); this._fetchURLLink(); this._fetchMyOrder(); this._fetchFlashSale(); this._fetchWantTo(); } }, [图片]
2021-11-21 - Unhandled promise rejection?
[图片] const promisic = function (n) { return function (t = {}) { return new Promise((c, r) => { const s = Object.assign(t, { success: n => { c(n) }, fail: n => { console.log("n---", n); r(n) } }); n(s) }) } }, async onTapAdd() { let { value: e, count: t, sizeType: a, maxImageSize: i } = this.data; const l = t - e.length; if (e.length >= t || l <= 0) return; const r = await promisic(wx.chooseImage)({ count: l, sizeType: a, sourceType: ["album", "camera"] }), s = [], n = []; console.log("r---140", r); r.tempFiles.forEach(e => { const { path: t, size: a } = e; a > i && i > 0 ? n.push(t) : s.push(t) }), this.setData({ value: e.concat(s) }, () => { const e = { all: this.data.value, current: s, oversize: n }; console.log("e---154", e); eventUtil.emit(this, "linadd", e), eventUtil.emit(this, "linchange", e), eventUtil.emit(this, "linoversize", e) }) },
2021-11-10 - “使用你的微信朋友信息”授权的接口文档在那里?
“使用你的微信朋友信息”这个接口文档在哪?描述这么写不好吧,估计90%的人都会拒绝。 [图片]
2021-11-08 - 云开发控制台,内容安全的规则配置?
请问,内容安全的规则配置不支持数组对象的嵌套字段吗? [图片]
2021-11-03 - 云函数Aggregate.geoNear()查询结果如何换算成米?
问题1: 云函数Aggregate.geoNear(),设置了maxDistance: 1000,希望只查询附近1公里的数据,没有符合条件的就不输出结果,但是现在是如果没有符合条件的就输出超过1000米的; app.router("RecommendPickUp", async (ctx, next) => { const result = await db.collection('PickUp') .aggregate() .geoNear({ distanceField: 'distance', // distanceMultiplier: 6378137, spherical: true, near: db.Geo.Point(event.longitude, event.latitude), maxDistance: 1000, limit: 9, // query: { // docType: 'geoNear', // }, key: 'location', includeLocs: 'location', }) .end() ctx.body = { data: result.list } }); 问题2: distanceField: 'distance', distanceMultiplier: 6378137, 如何设置可以将输出结果换算成米; [图片]
2021-11-01 - 内容管理登录网页端报错“您没有权限访问”?
[图片] [图片]
2021-10-25