0

Ich versuche das zurückgegebene Objekt der Sammlung zu filtern, die an easysearch übergeben wurde, basierend auf der Dokumentation hier [http://matteodem.github.io/meteor-easy-search/docs/recipes/][1]. Dies sollte Datensätze filtern und zurückgeben, die nur auf der angemeldeten userId basieren. Es gibt diesen Fehler mit falscher ID zurück. Ich weiß nicht genau, woher die ID kommt, weil die userId des angemeldeten Benutzers sich von der Suche unterscheidet. Bitte helfen sie aus.Meteor Easysearch filtert Benutzerdaten basierend auf dem angemeldeten Benutzer

Dies ist Easysearch Setup

// Client and Server 
SchoolStudentsIndex = new EasySearch.Index({ 

    engine: new EasySearch.MongoDB({ 
    sort: function() { 
     return { createdAt: -1}; 
    }, 
    selector(searchDefinition, options, aggregation) { 
     // retrieve the default selector 
     var selector = this.defaultConfiguration().selector(searchObject, options, aggregation) 

     // options.search.userId contains the userId of the logged in user 
     selector.owner = options.search.userId 

     return selector 
    }, 
    }), 
    collection: SchoolStudents, 
    fields: ['firstname', 'lastname', 'username', 'middlename', 'studentclass', 'address', 'city', 'state', 'country', 'registra'], 
    defaultSearchoptions: { 
    limit: 8 
    }, 
    permission: (options) => options.userId, // only allow searching when the user is logged in 
}); 

Fehler

I20170818-20:17:27.451(1)? Exception from sub schoolstudents/easySearch id RGBeuyLZybDvrwppj ReferenceError: searchObject is not defined 
    I20170818-20:17:27.456(1)?  at MongoDBEngine.EasySearch.Index.engine.EasySearch.MongoDB.selector (lib/collections/student.js:50:59) 
    I20170818-20:17:27.457(1)?  at MongoDBEngine.callConfigMethod (packages/easysearch:core/lib/core/engine.js:50:19) 
    I20170818-20:17:27.458(1)?  at MongoDBEngine.getSearchCursor (packages/easysearch:core/lib/engines/mongo-db.js:83:27) 
    I20170818-20:17:27.459(1)?  at MongoDBEngine.search (packages/easysearch:core/lib/core/reactive-engine.js:107:19) 
    I20170818-20:17:27.460(1)?  at [object Object].<anonymous> (packages/easysearch:core/lib/core/search-collection.js:177:43) 
    I20170818-20:17:27.461(1)?  at packages\matb33_collection-hooks.js:307:21 
    I20170818-20:17:27.462(1)?  at [object Object]._.extend.withValue (packages\meteor.js:1122:17) 
    I20170818-20:17:27.464(1)?  at [object Object]._handler (packages\matb33_collection-hooks.js:306:28) 
    I20170818-20:17:27.468(1)?  at packages\check.js:130:16 
    I20170818-20:17:27.471(1)?  at [object Object]._.extend.withValue (packages\meteor.js:1122:17) 


    [1]: http://matteodem.github.io/meteor-easy-search/docs/recipes/ 

zurückgegeben Dies ist der Client-Setup

inputAttributes: function() { 
    return {'class': 'easy-search-input', 'placeholder': 'Search Anything'}; 
    }, 

    players: function() { 
    return SchoolStudents.find({'userId': Meteor.userId()}, {sort: {createdAt: -1} }); 
    }, 

    selectedName: function() { 
    var students = SchoolStudentsIndex.config.mongoCollection.findOne({__originalId: Session.get('selectedStudents')}); 
    return students && students.firstname; 
    }, 

    index: function() { 
    return SchoolStudentsIndex; 
    }, 

    resultCount: function() { 
    return SchoolStudentsIndex.getComponentDict().get('count'); 
    }, 

    showMore: function() { 
    return false; 
    }, 
    renderTempl: function() { 
    Template.renderTemplate 
    } 

}); 

Template.UserStudents.helpers({ 
    selected: function() { 
    return Session.equals('selectedStudents', this.__originalId) ? 'selected' : ''; 
    } 
}); 

Dieses Setup Die Vorlage ist

<template name="student"> 
    {{#if currentUser}} 
    <div class="row uniform"> 
    <div class="12u$"> 
     <!-- search --> 
    <div id="search-wrap"> 

    <!-- Easy Search --> 
    <div class="row" style="margin-left: -50px; margin-top: -100px;"> 
    <div class="col-md-2"> 
     {{#unless uploading}} 
     <input type="file" name="uploadCSV" class="special"> 
     {{else}} 
     <p><i class="fa fa-spin fa-refresh"></i> Uploading files...</p> 
     {{/unless}} 
    </div> 
     <div class="black searchbar col-md-8">{{> EasySearch.Input index=index attributes=inputAttributes }}</div> 
     <button style="margin-right: 10px;" class="special" id="add-student-to-module" name="add-student-to-module">ADD TO MODULE</button> 
    </div> 
    <!-- search --> 
    <!-- Easy Search --> 
    <div><button name="invitestidents" class="button" id="invitestidents">INVITE STUDENTS</button></div> 
    <div><input type="checkbox" checked data-toggle="toggle" value="Select All"></div> 
    {{#EasySearch.IfInputEmpty index=index }} 
     <div class="padded examples black">For example "Abraham Jide Chukwudi"</div> 
    {{else}} 
     {{#if resultCount}} 
     <div class="padded count-results black">{{resultCount}} results found.</div> 
     {{/if}} 
    {{/EasySearch.IfInputEmpty}} 

    {{#EasySearch.IfSearching index=index }} 
     <div>Searching</div> 
    {{/EasySearch.IfSearching}} 

    <ol class="leaderboard"> 
     {{#EasySearch.Each index=index }} 
     {{> UserStudents}} 
     {{/EasySearch.Each}} 
    </ol> 

    {{#EasySearch.IfNoResults index=index }} 
     <div class="padded no-results black">No results found</div> 
    {{else}} 
    {{/EasySearch.IfNoResults}} 

    {{> EasySearch.Pagination index=index maxPages=20 }} 
    {{! > EasySearch.LoadMore index=index}} 

    {{#if showMore}} 
     {{> EasySearch.Input name="mini-index" index=index attributes=inputAttributes }} 
     <ul> 
     {{#EasySearch.Each name="mini-index" index=index}} 
      <li>{{name}}</li> 
     {{/EasySearch.Each}} 
     </ul> 

    {{/if}} 
    <!-- Easy Search --> 
    <!-- End search --> 
    </div> 
    </div> 
    </div> 
{{/if}} 
</template> 

<template name="UserStudents"> 

{{#if currentUser}} 
    <div class="row" style="margin-top: -50px;"> 
    <div class="container-pad" id="property-listings"> 
      <div class="row"> 
        <!-- Begin Listing: 609 W GRAVERS LN--> 
        <div class="brdr bgc-fff pad-10 box-shad btm-mrg-20 property-listing card-1"> 
         <div class="media"> 
         {{#if imagepath }} 
          <a class="pull-left" href="/student/{{slug}}" target="_parent"> 
          <img alt="image" class="img-responsive" src="{{imagepath}}" style="width: 70px; height: 70px; object-fit: contain;"></a> 
         {{else}} 
          <a class="pull-left" href="/student/{{slug}}" target="_parent"> 
          <img alt="image" class="img-responsive" src="/images/user_male_icon.png" style="width: 70px; height: 70px; object-fit: contain;"></a> 
         {{/if}} 
          <div class="clearfix visible-sm"></div> 

          <div class="media-body fnt-smaller"> 
           <a href="#" target="_parent"></a> 

           <h4 class="media-heading"> 
            <a href="/student/{{slug}}" target="_parent">{{firstname}} {{lastname}} <small class="pull-right">{{ createAt}}</small></a></h4> 


           <ul class="list-inline mrg-0 btm-mrg-10 clr-535353"> 
            <li><strong> {{username}}</strong></li> 

            <li style="list-style: none">|</li> 

            <li><strong>{{email}}</strong> {{mobile}} </li> 

            <li style="list-style: none"> | {{studentclass}}|</li> 

            <li><strong>{{address}}, {{city}}, {{state}}, {{country}} </strong></li> 
           </ul> 

           <!-- <p class="hidden-xs">{{trimString addschoolmission 0 260}}</p><span class="fnt-smaller fnt-lighter fnt-arial">Courtesy of HS Fox & Roach-Chestnut Hill 
           Evergreen</span>--> 
          </div> 
         </div> 
        </div><!-- End Listing--> 



       </div> 


     </div><!-- End container --> 

    </div> 
{{/if}} 
</template> 

JSon Probe von Benutzerdatensatz in der db

{ 
    "_id" : "Ge5ApePFGw5g25mRm", 
    "firstname" : "Kehinde", 
    "lastname" : "Adeoya", 
    "middlename" : "Adekusibe", 
    "username" : "ken4ward", 
    "password" : "CYfEJcFS", 
    "useremail" : "[email protected]", 
    "studentclass" : "ss2", 
    "dateofbirth" : "3-Mar-00", 
    "gender" : "m", 
    "ethinicity" : "black", 
    "mobile" : "8023472436", 
    "address" : "1 Abrahamoivc", 
    "city" : "bolson", 
    "lg" : "loveland", 
    "state" : "ekiti", 
    "country" : "Ukraine", 
    "registra" : "kadeoya", 
    "userId" : "KgQZnwqqzWL6D9x2T", 
    "createdAt" : ISODate("2017-08-18T19:17:39.593Z") 
} 

Antwort

1

Dieses wie ein Tippfehler aussieht, haben Sie:

selector(searchDefinition, options, aggregation) { 
    var selector = this.defaultConfiguration().selector(searchObject, options, aggregation) 

Ich glaube, Sie gemeint:

selector(searchDefinition, options, aggregation) { 
    var selector = this.defaultConfiguration().selector(searchDefinition, options, aggregation) 

Entweder das, oder Sie soll irgendwo searchObject definieren, aber vergessen zu.

Verwandte Themen