IBM Support

A query returns no results when including equal comparison on _id column in MongoDB wrapper

Troubleshooting


Problem

In MongoDB, each document in a collection requires a unique _id field that acts as a primary key.  If an inserted document omits this field, MongoDB automatically generates it. The _id field could be explicitly specified as a column when a nickname for MongoDB document is created in Db2 Federation. However, a query that including an equal comparison operator on this column might get an empty result set.

db2 => create nickname inventory (oid varchar(24) options(jpath '$._id.$oid'), item varchar(10) options(jpath '$.item')) for server JSERV options( doc 'inventory');
DB20000I  The SQL command completed successfully.
db2 => select * from inventory;
 
OID                      ITEM
------------------------ ----------
61ea66e9373e904b37c36414 canvas
61ea66f3373e904b37c36415 journal
61ea66f3373e904b37c36416 mat
61ea66f3373e904b37c36417 mousepad
 
  4 record(s) selected.
 
db2 => select * from inventory where oid = '61ea66e9373e904b37c36414';
 
OID                      ITEM
------------------------ ----------
 
  0 record(s) selected.

Document Location

Worldwide


[{"Type":"MASTER","Line of Business":{"code":"LOB10","label":"Data and AI"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SSEPGG","label":"Db2 for Linux, UNIX and Windows"},"ARM Category":[{"code":"a8m500000008PkvAAE","label":"Federation"}],"ARM Case Number":"","Platform":[{"code":"PF016","label":"Linux"}],"Version":"11.5.6;and future releases"}]

Log InLog in to view more of this document

This document has the abstract of a technical article that is available to authorized users once you have logged on. Please use Log in button above to access the full document. After log in, if you do not have the right authorization for this document, there will be instructions on what to do next.

Document Information

More support for:
Db2 for Linux, UNIX and Windows

Component:
Federation

Software version:
11.5.6 and future releases

Operating system(s):
Linux

Document number:
6837573

Modified date:
01 May 2025

UID

ibm16837573

Manage My Notification Subscriptions