首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Java Driver 3.8的ColdFusion & MongoDB 4

使用Java Driver 3.8的ColdFusion & MongoDB 4
EN

Stack Overflow用户
提问于 2018-08-03 00:08:50
回答 1查看 243关注 0票数 2

我正尝试在Mongo中使用Java11和MongoDB 4.0上的ColdFusion MongoDB驱动程序3.8执行通配符搜索。

下面的代码显示无法找到方法countDocuments()或方法find()的错误。

代码语言:javascript
复制
<cfset Mongo  = CreateObject("java","com.mongodb.MongoClient").init("localhost")>

<cffunction name="m" returntype="any">
    <cfargument name="value" type="any">
    <cfif IsJSON(arguments.value)>
        <cfset local.retrun = CreateObject("java","com.mongodb.util.JSON").parse(arguments.value)>
    <cfelse>
        <cfset local.retrun = CreateObject("java","com.mongodb.util.JSON").parse( SerializeJSON(arguments.value) )>     
    </cfif>
    <cfreturn local.retrun>
</cffunction>

<cfset db = Mongo.getDatabase('fda')>
<cfset DrugInfo = db.getCollection("druginfo")>

<cfset searchCount=druginfo.countDocuments(m({'openfda.brand_name':/Ty/ }))>

<cfset results  = DrugInfo.find(m({'openfda.brand_name': /Ty/})).iterator()>

当尝试执行精确匹配搜索时,一切工作正常。

代码语言:javascript
复制
<cfset searchCount=druginfo.countDocuments(m({'openfda.brand_name':'Tylenol'}))>

<cfset results  = DrugInfo.find(m({'openfda.brand_name': 'Tylenol'})).iterator()>

我基本上是在Mongo Compass中测试我的所有查询,并将它们粘贴到我的代码中,但它并没有像预期的那样工作。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51658025

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档