當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript mongodb.ObjectID類代碼示例

本文整理匯總了TypeScript中mongodb.ObjectID的典型用法代碼示例。如果您正苦於以下問題:TypeScript ObjectID類的具體用法?TypeScript ObjectID怎麽用?TypeScript ObjectID使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ObjectID類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: findOneById

  public findOneById(userId: string, markId: string): Promise<Mark> {
    assert(userId);
    assert(markId);

    const query = {
      "_id": ObjectID.createFromHexString(markId),
      "user._id": ObjectID.createFromHexString(userId)
    };

    return this.findOne(query);
  }
開發者ID:douglascvas,項目名稱:biblicando-backend,代碼行數:11,代碼來源:MarkDao.ts

示例2: it

 it('equal players with entity ids are equal', function () {
     const batman = {
         name: 'Batman',
         _id: ObjectID.createFromHexString('000000079bb31fb01ee7834c'),
         tribe: 'what'
     };
     const anotherBatman = {
         name: 'Batman',
         _id: ObjectID.createFromHexString('000000079bb31fb01ee7834c'),
         tribe: 'what'
     };
     expect(Comparators.areEqualPlayers(batman, anotherBatman)).toBe(true);
 })
開發者ID:robertfmurdock,項目名稱:Coupling,代碼行數:13,代碼來源:Comparators-spec.ts

示例3: Set

      const addIdsToQueryMap = (access: boolean) => (id: string | ObjectID) => {
        const accessString = access ? 'positive' : 'negative';
        const altAccessString = access ? 'negative' : 'positive';
        const resourceUid = Tyr.byName[linkedCollectionName].idToUid(id);

        if (alreadySet.has(resourceUid)) {
          return;
        } else {
          alreadySet.add(resourceUid);
        }

        const accessSet =
          queryMaps[accessString].get(linkedCollectionName) || new Set();
        if (!queryMaps[accessString].has(linkedCollectionName)) {
          queryMaps[accessString].set(linkedCollectionName, accessSet);
        }

        // if the id was set previously, by a lower level link,
        // dont override the lower level
        const map = queryMaps[altAccessString].get(linkedCollectionName);

        if (!map || !map.has(id.toString())) {
          accessSet.add(id as string);
        }
      };
開發者ID:tyranid-org,項目名稱:tyranid,代碼行數:25,代碼來源:query.ts

示例4: function

export default async function(ctx: Koa.Context) {
	// Validate id
	if (!mongodb.ObjectID.isValid(ctx.params.id)) {
		ctx.throw(400, 'incorrect id');
		return;
	}

	const fileId = new mongodb.ObjectID(ctx.params.id);

	// Fetch drive file
	const file = await DriveFile.findOne({ _id: fileId });

	if (file == null) {
		ctx.status = 404;
		await send(ctx, '/dummy.png', { root: assets });
		return;
	}

	if (file.metadata.deletedAt) {
		ctx.status = 410;
		await send(ctx, '/tombstone.png', { root: assets });
		return;
	}

	if (file.metadata.withoutChunks) {
		ctx.status = 204;
		return;
	}

	const sendRaw = async () => {
		const bucket = await getDriveFileBucket();
		const readable = bucket.openDownloadStream(fileId);
		readable.on('error', commonReadableHandlerGenerator(ctx));
		ctx.set('Content-Type', file.contentType);
		ctx.body = readable;
	};

	if ('thumbnail' in ctx.query) {
		const thumb = await DriveFileThumbnail.findOne({
			'metadata.originalId': fileId
		});

		if (thumb != null) {
			ctx.set('Content-Type', 'image/jpeg');
			const bucket = await getDriveFileThumbnailBucket();
			ctx.body = bucket.openDownloadStream(thumb._id);
		} else {
			await sendRaw();
		}
	} else {
		if ('download' in ctx.query) {
			ctx.set('Content-Disposition', 'attachment');
		}

		await sendRaw();
	}
}
開發者ID:ha-dai,項目名稱:Misskey,代碼行數:57,代碼來源:send-drive-file.ts

示例5: async

	connection.on('message', async (data) => {
		const msg = JSON.parse(data.utf8Data);

		switch (msg.type) {
			case 'read':
					if (!msg.id) {
						return;
					}

					const id = new mongodb.ObjectID(msg.id);

					// Fetch message
					// SELECT _id, user_id, is_read
					const message = await Message.findOne({
						_id: id,
						recipient_id: user._id
					}, {
						fields: {
							_id: true,
							user_id: true,
							is_read: true
						}
					});

					if (message == null) {
						return;
					}

					if (message.is_read) {
						return;
					}

					// Update documents
					await Message.update({
						_id: id
					}, {
						$set: { is_read: true }
					});

					// Publish event
					publishMessagingStream(message.user_id, user._id, 'read', id.toString());
				break;
		}
	});
開發者ID:syuilo,項目名稱:misskey-core,代碼行數:44,代碼來源:messaging.ts

示例6: findByVerse

  public findByVerse(userId: string, verseId: ObjectID, options: any): Promise<Mark[]> {
    assert(userId);
    assert(verseId);

    const query = {
      "user._id": ObjectID.createFromHexString(userId),
      "verse._id": verseId
    };

    return this.find(query, options);
  }
開發者ID:douglascvas,項目名稱:biblicando-backend,代碼行數:11,代碼來源:MarkDao.ts

示例7: it

    it("should correctly diff ObjectIDs", function () {
        let oldID = new MongoDB.ObjectID();
        let newID = MongoDB.ObjectID.createFromHexString(oldID.toHexString());

        let oldObject = { _id: oldID };
        let newObject = { _id: newID };
        let expectedDiff = {

        };

        chai.expect(Omnom.diff(oldObject, newObject)).to.exist.and.be.eql(expectedDiff);

        newID = new MongoDB.ObjectID();

        oldObject = { _id: oldID };
        newObject = { _id: newID };
        expectedDiff = {
            $set: { _id: newID }
        };

        chai.expect(Omnom.diff(oldObject, newObject)).to.exist.and.be.eql(expectedDiff);
    });
開發者ID:apapacy,項目名稱:Iridium,代碼行數:22,代碼來源:Omnom.ts

示例8: findByTag

  public findByTag(userId: string, tags: string[]): Promise<Mark[]> {
    assert(userId);
    assert(tags);

    const query = {
      "user._id": ObjectID.createFromHexString(userId),
      "tag": {
        $in: tags
      }
    };

    return this.find(query);
  }
開發者ID:douglascvas,項目名稱:biblicando-backend,代碼行數:13,代碼來源:MarkDao.ts

示例9: ObjectID

			return this.dbExecute<TEntity>((collection: Collection, subject: Subject<TEntity>) => {
				const id: ObjectID = new ObjectID(entity._id);
				delete entity._id;
				entity.lastUpdated = new Date();
				collection.replaceOne({ _id: id }, entity, (err: WriteError, result: UpdateWriteOpResult) => {
					if (err) {
						throw new Error(err.errmsg);
					}

					console.log(result.toString());
					entity._id = id.toHexString();
					subject.next(entity);
					subject.complete();
				});
			});
開發者ID:nickmorton,項目名稱:yes-admin,代碼行數:15,代碼來源:repository-base.ts

示例10: Error

				collection.replaceOne({ _id: id }, entity, (err: WriteError, result: UpdateWriteOpResult) => {
					if (err) {
						throw new Error(err.errmsg);
					}

					console.log(result.toString());
					entity._id = id.toHexString();
					subject.next(entity);
					subject.complete();
				});
開發者ID:nickmorton,項目名稱:yes-admin,代碼行數:10,代碼來源:repository-base.ts


注:本文中的mongodb.ObjectID類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。