COMMUNITY

How to write the same obj value as Mongodb?

– SQL:
SELECT * FROM UserInfo WHERE userName LIKE "%A%"

– MongoDB:
db.UserInfo.find({userName: /A/})

but haxe current not support

var obj={ "site" : /A/};

any suggestion? thanks.

update: fixed

use Syntax.code

That depends on a library you’re using to access MongoDB.

current we use dts2hx auto convert nodejs mongodb lib to haxe.

using tink.CoreApi;

    @await

    class Main {

        public static function main() {

        

            testMongodb();

        }

        @async

        public static function testMongodb() {

            var url = "mongodb://127.0.0.1:27017";

            var connect:MongoClient = @await Mongodb.connect(url, {useUnifiedTopology: true}).ofJsPromise();

            var test = connect.db("testdb").collection('test1');

            var effect = @await test.insertOne({"site": "runoob.com" + Random.int(1, 1000000)}).ofJsPromise();

            @await test.insertOne({"site": "runoob.com"}).ofJsPromise();

            @await test.update({"site": "runoob.com"}, {$set:{"site":"example.com"}}).ofJsPromise();

        

            @await test.deleteMany({ "site": /A/ }).ofJsPromise();//here is not support.

            var arr = @await test.find().toArray().ofJsPromise();

            trace(arr);

        }

    }

Then you should do it the same way it’s done in JS.
I guess /A/ is a regular expression literal which creates an instance of RegExp. So, in Haxe it may look like new js.lib.RegExp('A')